首页 > 解决方案 > 如何使用 java azure-storage-file-datalake 复制 Azure 存储文件/目录

问题描述

我使用azure-storage-file-datalake for java 在我的 Azure 存储帐户上进行文件系统操作,我可以打开文件、删除甚至重命名/移动文件或目录。

我找不到将文件/文件夹复制到其他位置的任何方法。

这就是我重命名/移动文件/目录的方式:

    DataLakeServiceClient storageClient = new DataLakeServiceClientBuilder().endpoint(endpoint).credential(credential).buildClient();
    DataLakeFileSystemClient dataLakeFileSystemClient = storageClient.getFileSystemClient("storage");
    DataLakeFileClient fileClient = dataLakeFileSystemClient.getFileClient("src/path");
    fileClient.rename("storage", "dest/path");

有没有其他方法可以使用azure-storage-file-datalakeSDK 甚至azure-storage-blobSDK 来复制文件或目录?

标签: javaazureazure-storageazure-data-lakeazure-storage-files

解决方案


我找到了一种使用com.azure.storage.blob.BlobClient.

使用beginCopy方法如下:

BlobServiceClient blobServiceClient = new BlobServiceClientBuilder().endpoint(spnEndpoint).credential(credential).buildClient();
BlobContainerClient blobContainerClient =  blobServiceClient.getBlobContainerClient("containerName");
BlobClient dst = blobContainerClient.getBlobClient("destination/blob");
BlobClient src = blobContainerClient.getBlobClient("src/blob");
dst.beginCopy(src.getBlobUrl(), null);

推荐阅读