forked from qiniu/java-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathListDemo.java
More file actions
46 lines (39 loc) · 1.71 KB
/
Copy pathListDemo.java
File metadata and controls
46 lines (39 loc) · 1.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import com.qiniu.common.QiniuException;
import com.qiniu.http.Response;
import com.qiniu.storage.BucketManager;
import com.qiniu.storage.model.FileInfo;
import com.qiniu.storage.model.FileListing;
import com.qiniu.util.Auth;
import com.qiniu.common.Zone;
import com.qiniu.storage.Configuration;
public class ListDemo {
public static void main(String args[]) {
//设置需要操作的账号的AK和SK
String ACCESS_KEY = "Access_Key";
String SECRET_KEY = "Secret_Key";
Auth auth = Auth.create(ACCESS_KEY, SECRET_KEY);
Zone z = Zone.zone0();
Configuration c = new Configuration(z);
//实例化一个BucketManager对象
BucketManager bucketManager = new BucketManager(auth, c);
//要列举文件的空间名
String bucket = "yourbucket";
try {
//调用listFiles方法列举指定空间的指定文件
//参数一:bucket 空间名
//参数二:prefix 文件名前缀
//参数三:marker 上一次获取文件列表时返回的 marker
//参数四:limit 每次迭代的长度限制,最大1000,推荐值 100
//参数五:delimiter 指定目录分隔符,列出所有公共前缀(模拟列出目录效果)。缺省值为空字符串
FileListing fileListing = bucketManager.listFiles(bucket, null, null, 10, null);
FileInfo[] items = fileListing.items;
for (FileInfo fileInfo : items) {
System.out.println(fileInfo.key);
}
} catch (QiniuException e) {
//捕获异常信息
Response r = e.response;
System.out.println(r.toString());
}
}
}