如何从数据湖检索文件路径位置?

时间:2021-03-22 23:53:09

标签: c# azure-data-lake-gen2

我正在关注 Azure 文档 here,它对代码示例感到困惑,目前我看到 sampleFilePathSampleFileContent 的错误“他们在这种情况下不存在”,他们没有记录...

        // Append data to the DataLake File
        file.Append(File.OpenRead(sampleFilePath), 0);
        file.Flush(SampleFileContent.Length);

        // Reading Data from a DataLake File
        Response<FileDownloadInfo> fileContents = file.Read();

        // Listing/Traversing through a DataLake Filesystem
        foreach (PathItem pathItem in filesystem.GetPaths())
        {
            names.Add(pathItem.Name);
        }
  1. 如何获取在数据湖上创建的示例文件路径 sampleFilePath 的位置?

1 个答案:

答案 0 :(得分:0)

sampleFilePath 只是一个文件路径,您可以在本地创建一个文件,然后将文件路径传递给它。像这样的代码:

        DataLakeFileSystemClient filesystem = serviceClient.GetFileSystemClient(Randomize("sample-filesystem"));
        filesystem.Create();

        DataLakeDirectoryClient directory = filesystem.GetDirectoryClient(Randomize("sample-file"));
        directory.Create();

        DataLakeFileClient file = directory.GetFileClient(Randomize("sample-file"));
        file.Create();

        string sampleFilePath = "D:\\test\\test.txt";
        FileStream SampleFileContent = File.OpenRead(sampleFilePath);

        // Append data to the DataLake File
        file.Append(File.OpenRead(sampleFilePath), 0);
        file.Flush(SampleFileContent.Length);

        // Reading Data from a DataLake File
        Response<FileDownloadInfo> fileContents = file.Read();