主要关键性代码,完全把这个地址:
http://love398146779.iteye.com/blog/2123802的全部代码copy下来即可。
我只补充两点他没有的。
①用到的关键性fastDFS的java client包是我把fastdfs_client_java._v1.25.tar.gz用ant命令生成的jar包,亲测有效,下载地址:
http://download.csdn.net/download/jianbo2233/10202609
②原作者对上传文件很详细了,我这补充下下载文件:
public static FileInfo getFile(String groupName, String remoteFileName) {
try {
byte[] download_file = storageClient.download_file(groupName, remoteFileName);
if (download_file!=null && download_file.length>0) {
String fString="D:\\fastDFS\\src" + File.separator + "col.png";
File file = new File(fString);
FileOutputStream fop = new FileOutputStream(file);
fop.write(download_file);
fop.close();
}
return storageClient.get_file_info(groupName, remoteFileName);
} catch (IOException e) {
logger.error("IO Exception: Get File from Fast DFS failed", e);
} catch (Exception e) {
logger.error("Non IO Exception: Get File from Fast DFS failed", e);
}
return null;
}
其中的路径和生成的文件名视实际需求修改。
然后根据自己设置的路径进去就可以找到相应的文件。