尝试在Azure中创建新存储桶时出现java.net.UnknownHostException

时间:2018-07-02 16:00:38

标签: java azure bucket

Exception in thread "main" java.util.NoSuchElementException: An error occurred while enumerating the result, check the original exception for details.
    at com.microsoft.azure.storage.core.LazySegmentedIterator.hasNext(LazySegmentedIterator.java:113)
    at com.test.maven.azureBlob.main(azureBlob.java:47)
Caused by: com.microsoft.azure.storage.StorageException: The server encountered an unknown failure: 
    at com.microsoft.azure.storage.StorageException.translateException(StorageException.java:101)
    at com.microsoft.azure.storage.core.ExecutionEngine.executeWithRetry(ExecutionEngine.java:199)
    at com.microsoft.azure.storage.core.LazySegmentedIterator.hasNext(LazySegmentedIterator.java:109)
    ... 1 more

以上是尝试从Java创建存储桶时遇到的异常

以下是代码 公共类azureBlob {     公共静态最终字符串storageConnectionString =             “ DefaultEndpointsProtocol = http;” +             “ AccountName =;” +             “ AccountKey =”;

public static void main(String[] args) throws InvalidKeyException, URISyntaxException, StorageException {
    // TODO Auto-generated method stub
    File sourceFile = null, downloadedFile = null;
    System.out.println("Azure Blob storage quick start sample");

    CloudStorageAccount storageAccount;
    CloudBlobClient blobClient = null;
    CloudBlobContainer container=null;

    storageAccount = CloudStorageAccount.parse(storageConnectionString);
    blobClient = storageAccount.createCloudBlobClient();
    container = blobClient.getContainerReference("quickstartcontainer");

    System.out.println("Creating container: " + container.getName());
    try
    {
    container.createIfNotExists();
    }
    catch (Exception e)
    {
        System.out.println(e.getMessage());
        }

    //Listing contents of container
    for (ListBlobItem blobItem : container.listBlobs()) {
    System.out.println("URI of blob is: " + blobItem.getUri());
}
}

}

1 个答案:

答案 0 :(得分:0)

我已经测试过您的代码,并且可以正常工作。

这是我的代码供您参考:

awk

结果截图:

enter image description here

请确保使用最新的Java SDK,我使用的Java SDK来自: azure-storage-java