java工具类fastdfs删除文件
public static void delete(String groupName, String remoteFilename) {
TrackerServer ts = null;
StorageServer ss = null;
try {
//加载FastDFS配置文件,用于获取所有的TrackerServer的地址
ClientGlobal.init("fastdfs.conf");
TrackerClient tc = new TrackerClient();
ts = tc.getConnection();
ss = tc.getStoreStorage(ts);
//创建Storage客户端对象,利用这个对象中的方法完成文件的上传下载和删除操作
StorageClient sc = new StorageClient(ts, ss);
/**
* 文件删除
* 参数 1 需要删除的文件所在组名
* 参数 2 需要删除的文件的远程文件名
* 返回一个int类型的数字,0表示文件删除成功 其他值表示文件删除失败
*/
int result = sc.delete_file(groupName, remoteFilename);
System.out.println(result);
} catch (IOException | MyException e) {
e.printStackTrace();
} finally {
if (ss != null) {
try {
ss.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if (ts != null) {
try {
ts.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}