【问题标题】:Trying to create file in datalake from webapp using java尝试使用java从webapp在datalake中创建文件
【发布时间】:2019-11-01 10:52:14
【问题描述】:

以下是在 datalake 中创建文件的一段代码。在 client.createfile 行抛出 ADLException。检查用户是否具有读、写和执行权限。有人可以帮助如何处理这个问题。

试试{

                     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());
                }

【问题讨论】:

  • 请不要提供代码图片。请查看How to Ask a Question,让您更好地了解如何以更有可能得到答案的方式组织问题。
  • @sql 您还有其他顾虑吗?

标签: java web-applications azure-active-directory azure-data-lake


【解决方案1】:

如果您想使用 Java 在 Azure Data Lake Gen1 中创建文件,我们可以使用 service-to-service authentication。详细步骤如下。

  1. Create an Active Directory web application

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

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

【讨论】:

  • @sql 您还有其他顾虑吗?
猜你喜欢
  • 1970-01-01
  • 2016-01-21
  • 1970-01-01
  • 1970-01-01
  • 2023-03-14
  • 1970-01-01
  • 2015-03-16
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多