标签:
?
?
Azure文件共享服务提供了多种方式的访问接口,包括Powershell,.Net, Java, Python等等,本章主要介绍如何使用Java来访问Azure File存储。
?
http://cloudapps.blog.51cto.com/3136598/1772092
?
public static final String storageConnectionString =
???????? "DefaultEndpointsProtocol=http;" +
???????? "AccountName=mystorageacctfile;" +
???????? "AccountKey=YOURStorageAccountKey;" +
???????? "EndpointSuffix=core.chinacloudapi.cn";
?
如果需要进行加密传输,修改DefaultEndpointsProtocol=https.
?
具体命名规则请参考:https://msdn.microsoft.com/library/azure/dn167011.aspx
storageAccount = CloudStorageAccount.parse(storageConnectionString);
???????? System.out.println(storageAccount.getBlobEndpoint());
???????? ?
???????? CloudFileClient fileClient = storageAccount.createCloudFileClient();
?
CloudFileShare share = fileClient.getShareReference(myFileShare);
????????
if (share.createIfNotExists())
{
System.out.println("New file share:" + myFileShare +"created!");
}
?
//Get a reference to the root directory for the share.
CloudFileDirectory rootDir = share.getRootDirectoryReference();
????????
//Get a reference to the sampledir directory
CloudFileDirectory sampleDir = rootDir.getDirectoryReference(mydirectory);
?
if (sampleDir.createIfNotExists())
{
System.out.println("sampledir created");
}
else {
System.out.println("sampledir already exists");
}
//upload a test file to the sampledir
CloudFile cloudFile = sampleDir.getFileReference("hdinsight.publishsettings");
????????
if(!cloudFile.exists())
{
????cloudFile.uploadFromFile(testfilePath);
}
else
{
????//Download file if exists
????System.out.println(cloudFile.downloadText());
}
?
CloudFile cloudFile = sampleDir.getFileReference(testFilename);
????//Delete specified file
????if ( cloudFile.deleteIfExists() )
{
???? System.out.println(testFilename + " was deleted!");
????????
}
?
//Get a reference to the root directory for the share.
CloudFileDirectory rootDir = share.getRootDirectoryReference();
???????? ?
//Get a reference to the sampledir directory
CloudFileDirectory sampleDir = rootDir.getDirectoryReference(mydirectory);
// Delete the directory
if ( sampleDir.deleteIfExists() )
{
???? System.out.println("Directory "+ sampleDir +" was deleted!");
}
?
10.关于在你调用Azure file接口的时候,使用https链接,即将链接字符串中的DefaultEndpointsProtocol设置为https,你可能会碰到如下错误:
?
即使你使用的是最新的Azure China 的WoSign的证书,也会出现上述问题,具体原因和Azure China没有关系,你懂的:)解决办法请参考我的博文:
?
http://cloudapps.blog.51cto.com/3136598/1744342
?
标签:
原文地址:http://www.cnblogs.com/cloudapps/p/5486887.html