gpt4 book ai didi

java - 尝试使用java从webapp在datalake中创建文件

转载 作者:行者123 更新时间:2023-12-01 22:11:29 24 4
gpt4 key购买 nike

下面是在数据湖中创建文件的代码段。 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 。详细步骤如下。

  1. Create an Active Directory web application enter image description here

  2. Assign the Azure AD application to the Azure Data Lake Storage Gen1 account file or folder enter image description here

  3. 代码

 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://learn.microsoft.com/en-us/azure/data-lake-store/data-lake-store-get-started-java-sdk .

关于java - 尝试使用java从webapp在datalake中创建文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58657968/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com