java调用minio查看桶中的文件夹是否存在
时间: 2024-09-23 22:02:19 浏览: 165
在Java中,使用MinIO SDK来检查MinIO存储桶中的文件夹是否存在,首先需要设置连接到MinIO服务器所需的凭据,例如endpoint、access key和secret key。以下是一个简单的步骤示例:
```java
import io.minio.MinioClient;
import io.minio.errors.MinioException;
public class MinioFolderExistenceCheck {
private static final String MINIO_ENDPOINT = "your-minio-endpoint";
private static final String ACCESS_KEY = "your-access-key";
private static final String SECRET_KEY = "your-secret-key";
private static final String BUCKET_NAME = "your-bucket-name";
private static final String FOLDER_PATH = "/your-folder-path";
public static void main(String[] args) {
try {
// 创建Minio客户端
MinioClient minioClient = new MinioClient(MINIO_ENDPOINT, ACCESS_KEY, SECRET_KEY);
// 检查文件夹是否存在
boolean folderExists = minioClient.bucketExists(BUCKET_NAME, FOLDER_PATH);
if (folderExists) {
System.out.println("Folder " + FOLDER_PATH + " exists in bucket " + BUCKET_NAME);
} else {
System.out.println("Folder " + FOLDER_PATH + " does not exist in bucket " + BUCKET_NAME);
}
// 关闭连接
minioClient.close();
} catch (MinioException e) {
System.err.println("Error checking folder existence: " + e.getMessage());
}
}
}
```
在这个例子中,`bucketExists`方法会返回布尔值,如果文件夹存在则为true,反之为false。
阅读全文