代码简洁又实用 /** * 断点下载文件 */ public boolean download(String remote, String local) throws IOException { ftpClient.enterLocalPassiveMode(); ftpClient.setFileType(FTP.BINARY_FILE_TYPE); boolean result; File f = new File(local); File ffinish = new File(local.substring(0, local.lastIndexOf("."))); // 根据remote获取ftp上的文件名 FTPFile[] files = ftpClient.listFiles(remote); if (files.length != 1) { return false; } long lRemoteSize = files[0].getSize(); // 检查本地文件是否存在 if (ffinish.exists()) { return false; } if (f.exists()) { OutputStream out = new FileOutputStream(f, true); ftpClient.setRestartOffset(f.length()); result = ftpClient.retrieveFile(remote, out); out.close(); } else { OutputStream out = new FileOutputStream(f); result = ftpClient.retrieveFile(remote, out); out.close(); } // 文件下载中止 if (f.length() >= lRemoteSize) { f.renameTo(new File(local.substring(0, local.lastIndexOf(".")))); } return result; }
- 粉丝: 1
- 资源: 9
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
- 1
- 2
前往页