以下是在datalake中创建文件的代码段。 ADLException抛出在client.createfile行。经许可检查,用户已读取,写入和执行。有人可以帮忙解决这个问题吗?
尝试{
OutputStream stream = client.createFile("/Raw/TEST/"+FuFileName, IfExists.OVERWRITE);
PrintStream out = new PrintStream(stream);
for (int i = 1; i <= 10; i++) {
out.println("This is line #" + i);
out.format("This is the same line (%d), but using formatted output. %n", i);
}
out.close();
} catch (ADLException ex) {
printExceptionDetails(ex);
} catch (Exception ex) {
System.out.format(" Exception: %s%n Message: %s%n", ex.getClass().getName(), ex.getMessage());
}
最佳答案
如果要使用Java在Azure Data Lake Gen1中创建文件,可以使用service-to-service authentication。详细步骤如下。
Create an Active Directory web application
Assign the Azure AD application to the Azure Data Lake Storage Gen1 account file or folder
码
private static String clientId = "FILL-IN-HERE";
private static String authTokenEndpoint = "FILL-IN-HERE";
private static String clientKey = "FILL-IN-HERE";
AccessTokenProvider provider = new ClientCredsTokenProvider(authTokenEndpoint, clientId, clientKey);
private static String accountFQDN = "FILL-IN-HERE"; // full account FQDN, not just the account name
ADLStoreClient client = ADLStoreClient.createClient(accountFQDN, provider);
try {
String filename = "/a/b/c.txt";
OutputStream stream = client.createFile(filename, IfExists.OVERWRITE );
PrintStream out = new PrintStream(stream);
for (int i = 1; i <= 10; i++) {
out.println("This is line #" + i);
out.format("This is the same line (%d), but using formatted output. %n", i);
}
out.close();
System.out.println("File created.");
}catch(Exception ex){
System.out.format(" Exception: %s%n Message: %s%n", ex.getClass().getName(), ex.getMessage());
}
有关更多详细信息,请参阅https://docs.microsoft.com/en-us/azure/data-lake-store/data-lake-store-get-started-java-sdk。
关于java - 尝试使用Java从Web应用程序在Data Lake中创建文件,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/58657968/