Search code examples
javaazureazure-storageazure-data-lakeazure-storage-files

How to copy Azure storage files/directories using java azure-storage-file-datalake


I use azure-storage-file-datalake for java to make file system operations on my Azure storage account, I can open files, delete, and even rename/move files or directories.

I can't find any way to copy files/folder to other location.

That's how I rename/move files/directories:

    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");

Is there any other method I can use to copy files or directories using the azure-storage-file-datalake SDK or even the azure-storage-blob SDK?


Solution

  • I found a method to copy blobs(files) within the same storage account using com.azure.storage.blob.BlobClient.

    using beginCopy method as follows:

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