2016-05-10 8 views

答えて

0

CloudFile.startCopy(source)を使用して、BLOBファイルの名前を変更してコピーすることができます。そしてここに完全なコードがあります。

package nau.edu.cn.steven; 

import com.microsoft.azure.storage.CloudStorageAccount; 
import com.microsoft.azure.storage.file.CopyStatus; 
import com.microsoft.azure.storage.file.CloudFile; 
import com.microsoft.azure.storage.file.CloudFileClient; 
import com.microsoft.azure.storage.file.CloudFileDirectory; 
import com.microsoft.azure.storage.file.CloudFileShare; 

public class AzureCopyFile { 

     // Connection string 
     public static final String storageConnectionString = 
    "DefaultEndpointsProtocol=http;" 
    + "AccountName=your_account_name;" 
    + "AccountKey= your_account_key"; 

     public static void main(String[] args) 
     { 
      try { 

       CloudStorageAccount account = CloudStorageAccount.parse(storageConnectionString); 
       CloudFileClient fileClient = account.createCloudFileClient(); 

       // Get a reference to the file share 
       CloudFileShare share = fileClient.getShareReference("sampleshare"); 

       if(share.createIfNotExists()) { 
        System.out.println("New share created"); 
       } 

       // Get a reference to the root directory for the share for example 
       CloudFileDirectory rootDir = share.getRootDirectoryReference(); 

       // Old file 
       CloudFile oldCloudFile = rootDir.getFileReference("Readme.txt"); 
       // New file 
       CloudFile newCloudFile = rootDir.getFileReference("Readme2.txt"); 
       // Start copy 
       newCloudFile.startCopy(oldCloudFile.getUri()); 

       // Exit until copy finished 
       while(true) { 
        if(newCloudFile.getCopyState().getStatus() != CopyStatus.PENDING) { 
         break; 
        } 

        // Sleep for a second maybe 
        Thread.sleep(1000); 
       } 
      } 
      catch(Exception e) { 
       System.out.print("Exception encountered: "); 
       System.out.println(e.getMessage()); 
       System.exit(-1); 
      } 
     } 
} 
+0

blobは、CloudFileからの名前の変更やコピーを実現する他の方法ではありません。cloudFile = sampleDir.getFileReference( "filename"); – madhavan

+0

はい、回答を更新しました。 – Steven

+0

私はstartCopy(cloudfile.getUri)を使ってコピーできます。使用可能な場合は、javaを使用して空のストレージのファイルの名前を変更する方法はありますか? – madhavan

0

は、AzureのファイルストレージのクラスCloudFileのjavadocによると、さえブロブストレージのファイルストレージ用のネイティブサポートなし名前変更操作はありません。

名前変更アクションを実行するには、新しい名前のファイルをコピーして古い名前でファイルを削除する2つの手順を実行する必要があります。

MSDNとは別に、2つのスレッドがSO &以下にあります。

  1. Programmatically (.NET) renaming an Azure File or Directory using File (not Blob) StorageこれはJavaを使用した場合と同じです。
  2. https://social.msdn.microsoft.com/Forums/azure/en-US/04c415fb-cc1a-4270-986b-03a68b05aa81/renaming-files-in-blobs-storage?forum=windowsazuredata

@スティーブン氏によると、コピー操作は、新しいファイル参照のために機能startCopyによってサポートされています。

関連する問題