公司要求把FTP上的文件读取完后移动到另一个文件中,我用了在网上查的ftpClient.rename没有反应,请各位大神支招
问题我解决了,在所有的代码执行完成后再去执行ftpClient.rename(),具体原因没有找到
/**
* 上传文件到FTP服务器
* @param localPathAndFileName 本地文件目录和文件名
* @param fileName 上传后的文件名,如果为null,则上传文件名与本地文件名相同
* @param remotePath
* @throws Exception
*/
public boolean put (String localFile,String fileName ,String remotePath ) throws Exception{
TelnetOutputStream os = null;
FileInputStream is =null;
if(fileName==null || fileName.equals("")){
fileName=new File(localFile).getName();
}
try {
if (!open()) {
return false;
}
if (remotePath!=null&&remotePath.length()>0)
cd(remotePath);
os = ftpClient.put(fileName);
File in = new File(localFile);
is = new FileInputStream(in);
byte bytes[] = new byte[1024];
int readBytes;
while ((readBytes=is.read(bytes))!=-1) {
os.write(bytes, 0, readBytes);
}
} catch (Exception e) {
//Log.writeLog("ftp server: upload file failed",e);
logger.info("ftp server: upload file failed"+e);
return false;
} finally {
if (is!=null)
is.close();
if (os!=null)
os.close();
}
return true;
}
你这个不就是ftp的上传功能吗。jre用1.6的。