我正在尝试使用azure docs网站(https://docs.microsoft.com/en-us/azure/java/java-sdk-azure-get-started
上给出的Java代码示例)访问文件共享以从中上传和下载文件。我有一个microsoft azure存储帐户设置,上面有一个文件的文件共享,我按照示例使用了正确的连接字符串。目前,我正在通过一条测试代码运行此代码,并使用一个主要方法来调用上载或下载方法,将其作为Java应用程序运行或调试,但出现错误:503服务不可用。
任何人都可以建议导致此问题的原因,或者如果我应该遵循其他/进一步/更好的说明集?
编辑:为响应下面的第一个答复,这是代码示例:
import java.io.IOException;
import java.net.URISyntaxException;
import java.security.InvalidKeyException;
import com.microsoft.azure.storage.*;
import com.microsoft.azure.storage.file.*;
/**
* Coded based on "Develop for Azure files with Java" tutorial from here:
* https://docs.microsoft.com/en-au/azure/storage/files/storage-java-how-to-use-file-storage
*/
public class myAzureExample {
// Configure the connection-string with your values
public static final String storageConnectionString =
"DefaultEndpointsProtocol=http;" +
"accountName=myaccountName;" +
"accountKey=myaccountKey";
public static void main(String[] args) throws URISyntaxException,StorageException,InvalidKeyException,IOException {
downloadFile();
}
public static void downloadFile() throws InvalidKeyException,URISyntaxException,IOException {
CloudFileShare share = getShare();
//Get a reference to the root directory for the share.
CloudFileDirectory rootDir = share.getRootDirectoryReference();
//Get a reference to the directory that contains the file
CloudFileDirectory sampleDir = rootDir.getDirectoryReference("sampledir");
//Get a reference to the file you want to download
CloudFile file = sampleDir.getFileReference("SampleFile.txt");
//Write the contents of the file to the console.
System.out.println(file.downloadText());
}
private static CloudFileShare getShare() throws URISyntaxException,StorageException {
CloudStorageaccount storageaccount = CloudStorageaccount.parse(storageConnectionString);
CloudFileclient fileclient = storageaccount.createcloudFileclient();
// Get a reference to the file share
CloudFileShare share = fileclient.getShareReference("portalshare");
return share;
}
}