forked from qiniu/java-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmove.java
More file actions
35 lines (30 loc) · 1.23 KB
/
Copy pathmove.java
File metadata and controls
35 lines (30 loc) · 1.23 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
import com.qiniu.common.QiniuException;
import com.qiniu.http.Response;
import com.qiniu.storage.BucketManager;
import com.qiniu.util.Auth;
import com.qiniu.common.Zone;
import com.qiniu.storage.Configuration;
public class BucketManagerDemo {
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);
//要测试的空间和key,并且这个key在你空间中存在
String bucket = "Bucket_Name";
String key = "Bucket_key";
//将文件从文件key移动到文件key2, 可以在不同bucket移动,同空间移动相当于重命名
String key2 = "yourjavakey";
try {
//调用move方法移动文件
bucketManager.move(bucket, key, bucket, key2);
} catch (QiniuException e) {
//捕获异常信息
Response r = e.response;
System.out.println(r.toString());
}
}