FtpClient 复制文件功能问题 Ftpftpclient 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 我这段代码的问题是卡死在: if (!ftpClient.completePendingCommand()) { copyFalg = false; return copyFalg; }用标准的文件传输方式,放在缓存里谩慢的读是什么意思?能否讲的更清楚一些?谢谢 FileInputStream fis = null; FileOutputStream fos = null; byte[] buffer = new byte[100]; int temp = 0; try{ fis = new FileInputStream("a"); fos = new FileOutputStream("b"); while(true){ temp = fis.read(buffer,0,buffer.length); if(temp == -1){ break; } fos.write(buffer,0,temp); } } catch(Exception e){ System.out.println(e); } finally{ try{ fis.close(); fos.close(); } catch(Exception e2){ System.out.println(e2); } } 这段代码只是基本的本地文件复制。我上面的代码是,通过FTP连接到FTP服务器进行远程文件的复制。和你说的不相同。inputStream = ftpClient.retrieveFileStream(from + PATH_SLASH + category); // 复制文件时掉用了retrieveFileStream方法 // 调用完之后必须调用completePendingCommand释放,否则FTP会断开连接 if (!ftpClient.completePendingCommand()) { copyFalg = false; return copyFalg; } // 如果读取的文件流不为空则复制文件 if (inputStream != null) { copyFalg = ftpClient.storeFile(to + PATH_SLASH + category, inputStream); // 关闭文件流 inputStream.close(); if (!copyFalg) { return copyFalg; } }这段代码就是在读取远程的某个文件,然后复制到新的地方。我也做了修改, inputStream = ftp.retrieveFileStream(fromFilePath); ftp.setDataTimeout(10000000); if (!ftp.completePendingCommand()) { success = false; return success; } outputStream = ftp.storeFileStream(toFilePath); byte[] buf = new byte[1024 * 16]; int size = 0; while ((size = inputStream.read(buf)) != -1){ outputStream.write(buf, 0, size); }但是还是出现 超过100KB的文件就复制不成功,小于100KB的文件就能偶复制成功。 你要先关闭流 inputStream.close();,然后再执行ftp.completePendingCommand,否则会出现问题 楼主,我也遇到了一样的问题,我最终解决方案是这样,将文件读到内存中去操作..不多说上代码,16Mb文件copy成功. client.setBufferSize(1024); ByteArrayOutputStream fos=new ByteArrayOutputStream(); client.retrieveFile(path+name, fos); ByteArrayInputStream in=new ByteArrayInputStream(fos.toByteArray()); client.storeFile(path+newfilename, in); fos.close(); in.close(); JAVA写的单件模式 如何提取网页上表格中的数据,望大侠指点! 面对大数据量同步的困惑 如何更新txt文件中特定的一部分?在线等~ Java编程时如何设置让JFrame最大化显示? 我的程序为什么不能编译通过?错在哪里?各位大侠帮帮忙啊! jboss 求教 照书输了一段程序,但是编译通不过,说是有一个class没定义让定义成abstract,可是.... switch语句问题 怎样在页面上控制“记住网站密码”功能??? try后面一定要有catch吗
if (!ftpClient.completePendingCommand()) {
copyFalg = false;
return copyFalg;
}
用标准的文件传输方式,放在缓存里谩慢的读是什么意思?能否讲的更清楚一些?谢谢
FileInputStream fis = null;
FileOutputStream fos = null;
byte[] buffer = new byte[100];
int temp = 0;
try{
fis = new FileInputStream("a");
fos = new FileOutputStream("b");
while(true){
temp = fis.read(buffer,0,buffer.length);
if(temp == -1){
break;
}
fos.write(buffer,0,temp);
}
}
catch(Exception e){
System.out.println(e);
}
finally{
try{
fis.close();
fos.close();
}
catch(Exception e2){
System.out.println(e2);
}
}
我上面的代码是,通过FTP连接到FTP服务器进行远程文件的复制。
和你说的不相同。inputStream = ftpClient.retrieveFileStream(from + PATH_SLASH + category);
// 复制文件时掉用了retrieveFileStream方法
// 调用完之后必须调用completePendingCommand释放,否则FTP会断开连接
if (!ftpClient.completePendingCommand()) {
copyFalg = false;
return copyFalg;
}
// 如果读取的文件流不为空则复制文件
if (inputStream != null) {
copyFalg = ftpClient.storeFile(to + PATH_SLASH + category, inputStream);
// 关闭文件流
inputStream.close();
if (!copyFalg) {
return copyFalg;
}
}
这段代码就是在读取远程的某个文件,然后复制到新的地方。我也做了修改,
inputStream = ftp.retrieveFileStream(fromFilePath);
ftp.setDataTimeout(10000000);
if (!ftp.completePendingCommand()) {
success = false;
return success;
}
outputStream = ftp.storeFileStream(toFilePath); byte[] buf = new byte[1024 * 16];
int size = 0;
while ((size = inputStream.read(buf)) != -1){
outputStream.write(buf, 0, size);
}但是还是出现 超过100KB的文件就复制不成功,小于100KB的文件就能偶复制成功。
client.setBufferSize(1024);
ByteArrayOutputStream fos=new ByteArrayOutputStream();
client.retrieveFile(path+name, fos);
ByteArrayInputStream in=new ByteArrayInputStream(fos.toByteArray());
client.storeFile(path+newfilename, in);
fos.close();
in.close();