Spire.Cloud.Storage Java SDK 给开发人员提供了 FolderApi 接口,支持新建、移动、复制、下载及删除夹。本文将介绍如何调用 FolderApi 接口操作文件夹。
首先:通过 Maven 仓库安装 Spire.Cloud.SDK jar 包及依赖,详细步骤可参考这篇文章。
其次:通过冰蓝云官网(https://cloud.e-iceblue.cn/)注册账号并登陆,在“我的应用”创建应用程序,获得 App ID 及 App Key。
新建文件夹:
import spire.cloud.storage.sdk.Configuration;
import spire.cloud.storage.sdk.api.FolderApi;
public class CloudWord {
static String appId = "Your App ID";
static String appKey = "Your App Key";
static String baseUrl = "https://api.e-iceblue.cn";
//配置App ID和App Key
static Configuration configuration = new Configuration(appId, appKey, baseUrl);
//创建FolderApi实例
static FolderApi folderApi = new FolderApi(configuration);
public static void main(String[] args) throws Exception {
//新建文件夹
String path = "input";
String storageName = null;
folderApi.createFolder(path, storageName);
}
}
新建文件夹示例图:
复制、删除及移动文件夹:
import spire.cloud.storage.sdk.Configuration;
import spire.cloud.storage.sdk.api.FolderApi;
public class CloudWord {
static String appId = "Your App ID";
static String appKey = "Your App Key";
static String baseUrl = "https://api.e-iceblue.cn";
//配置App ID和App Key
static Configuration configuration = new Configuration(appId, appKey, baseUrl);
//创建FolderApi实例
static FolderApi folderApi = new FolderApi(configuration);
public static void main(String[] args) throws Exception {
//复制文件夹
String srcPath = "input";
String destPath = "output/CopyFolderTest";
String srcStorageName = null;
String destStorageName = null;
folderApi.copyFolder(srcPath, destPath, srcStorageName, destStorageName);
}
//删除文件夹
public static void deleteFolder() throws Exception{
String path = "output/test";
String storageName = null;
Boolean recursive = true;
folderApi.deleteFolder(path, storageName, recursive);
}
//移动文件夹
public static void moveFolder() throws Exception{
String srcPath = "input";
String destPath = "output/clone";
String srcStorageName = null;
String destStorageName = null;
folderApi.moveFolder(srcPath, destPath, srcStorageName, destStorageName);
}
}