gpt4 book ai didi

java - 使用 Java 删除 Azure Blob 存储中的文件夹

转载 作者:行者123 更新时间:2023-12-03 02:17:04 27 4
gpt4 key购买 nike

如何删除 Azure Blob 存储中的文件夹。当我尝试删除文件夹时,我看到以下错误:

com.azure.storage.blob.models.BlobStorageException: Status code 409,"DirectoryIsNotEmptyThisoperation is not permitted on a non-empty directory.RequestId:195b3f66-601e-0071-2edb-094790000000Time:2022-01-15T06:47:55.8443865Z"

at sun.reflect.NativeConstructorAccessorImpl.newInstance0(NativeMethod) atsun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)atsun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)at java.lang.reflect.Constructor.newInstance(Constructor.java:423)atcom.azure.core.http.rest.RestProxy.instantiateUnexpectedException(RestProxy.java:389)atcom.azure.core.http.rest.RestProxy.lambda$ensureExpectedStatus$7(RestProxy.java:444)

最佳答案

不确定以下版本是否是最优化的版本。但它似乎有效:

public static void deleteAtLocation(BlobContainerClient container, String historical) {
if (checkIfPathExists(container, historical)) {
List<BlobItem> collect = container.listBlobsByHierarchy(historical).stream().collect(Collectors.toList());
for (BlobItem blobItem : collect) {
String name = blobItem.getName();
if (name.endsWith("/")) {
deleteAtLocation(container, name);
} else container.getBlobClient(name).delete();
}
container.getBlobClient(historical.substring(0, historical.length() - 1)).delete();
}
}

public static boolean checkIfPathExists(BlobContainerClient container, String filePath) {
BlobClient blobClient = container.getBlobClient(filePath);
return blobClient.exists();
}

关于java - 使用 Java 删除 Azure Blob 存储中的文件夹,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70719419/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com