私は、JavaサービスによってAzureストレージアカウントにディレクトリを作成しています。Javaでazureの親ディレクトリの下にサブディレクトリを追加するには?
JSON入力は次のとおりです。
{ "accountName" : "name",
"accountkey" : "keyOfAzureAccount",
"directoryStructure" : "directory1/directory2/directory3/directory4/directory5"
}
私は期待してい何紺碧のアカウントで1アンダー-1これらのディレクトリを作成することです。ディレクトリ5と同様に、ディレクトリ4内にあります。 directory4はdirectory3の内部にあります。 directory3はdirectory2の内側にあり、directory2はdirectory1の内側にあります。
私のJavaコードは次のようである:
@Override
public JSONObject createDynamicDirectory(JSONObject jsonInput) throws InvalidKeyException, URISyntaxException {
CloudFileClient fileClient = null;
String storageConnectionString = "DefaultEndpointsProtocol=https;AccountName="+jsonInput.get("accountName")+";"+"AccountKey="+jsonInput.get("accountkey");
System.out.println(storageConnectionString);
CloudStorageAccount storageAccount = CloudStorageAccount.parse(storageConnectionString);
JSONObject jsonOutput = new JSONObject();
try {
fileClient = storageAccount.createCloudFileClient();
String directoryName = jsonInput.get("directoryStructure").toString();
String[] directoryNameArray = directoryName.split("\\s*/\\s*");
System.out.println(directoryNameArray.length);
CloudFileShare share = fileClient
.getShareReference(directoryNameArray[0].toLowerCase().replaceAll("[-+.^:,[email protected]#$%&*()_~`]", ""));
if (share.createIfNotExists()) {
System.out.println("New share created named as "
+ directoryName.toLowerCase().replaceAll("[-+.^:,[email protected]#$%&*()_~`]", ""));
}
for(int i=0;i<directoryNameArray.length;i++)
{
CloudFileDirectory rootDir = share.getRootDirectoryReference();
CloudFileDirectory parentDirectory = rootDir.getDirectoryReference(directoryNameArray[i]);
if (parentDirectory.createIfNotExists()) {
System.out.println("new directory created named as " + directoryName);
jsonOutput.put("status", "successful");
}
}
} catch (Exception e) {
System.out.println("Exception is " + e);
jsonOutput.put("status", "unsuccessful");
jsonOutput.put("exception", e.toString());
}
return jsonOutput;
}
}
必要に応じて、このコードは、directory1のからシェアを作成します。しかし、問題は、同じ共有の下で、すべてのディレクトリ1,2,3,4,5を作成することです。必要に応じて1対1のディレクトリに似ていません。
ディレクトリを必要に応じて作成できるように、Javaコードを実装するにはどうすればよいですか?
ありがとうございます。出来た。 –
こんにちは、次の質問をご覧ください:https://stackoverflow.com/questions/44236289/how-to-copy-file-from-one-directory-to-other-in-azure-through-java-service –