如何在ftp server中改变ascii或binary传输模式? 这个不是由于ascii和binary的问题,主要是Linux和Windows的换行符是不一样所致 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 如果是ascii模式,你可以在接收了每一行之后只插入\r不要\r\n 多出那个^M是必然的,两个系统对回车换行的理解是不一样的用bi可以指定上传用二进制方式对于已经上传了文件,你可以在vi中,用::%s/^V^M//g把所有的^M都删除掉! 接受ascii和binary文件,应该用不同的流读取,你可以先判断文件的类型,然后根据类型:ascii用 BufferedReader或其他Reader 来读取;bin用 DataInputStream来读取。 import java.io.*;import sun.net.ftp.FtpClient;public class FtpExample { public static void main(String args[]) throws Exception { FtpClient fc; String host = args[0]; String path = args[1]; String username = args[2]; String password = args[3]; int lastSlash = path.lastIndexOf('/'); String filename = path.substring(lastSlash+1); String directory = path.substring(0,lastSlash); FtpClient client = new FtpClient(host); client.login(username, password); client.binary(); client.cd(directory); InputStream is = client.get(filename); BufferedInputStream bis = new BufferedInputStream(is); OutputStream os = new FileOutputStream(filename); BufferedOutputStream bos = new BufferedOutputStream(os); byte[] buffer = new byte[1024]; int readCount; System.out.println("Getting: " + filename); while( (readCount = bis.read(buffer)) > 0) { bos.write(buffer, 0, readCount); } bos.close();// client.closeServer(); }} http://java.sun.com/docs/books/tutorial/networking/ java 窗体传值的问题 一个页面获取汉字的乱码问题---在线等 问个数组的问题 eclipse连接SQL2000出错拉!各位帮忙解决下~~~ swing中布局的问题 大家能推荐几本JAVA书给小弟吗? 这句为什么会出错? 关于多行表格列头部的代码,看看为什么就是不能多行显示(JAVA2图形设计SWING里的源程序) 在java中如何调用打开方式在新窗口中显示一文件,如显示一图片 spring查询多个表中的字段 简单问题:谁知道改变屏幕的一块区域的颜色的函数是什末? 在《java2核心技术》卷I中第102页的CardDeck是如何调用第103页的Card的toString方法的?
用bi可以指定上传用二进制方式对于已经上传了文件,你可以在vi中,用:
:%s/^V^M//g
把所有的^M都删除掉!
你可以先判断文件的类型,然后根据类型:
ascii用 BufferedReader或其他Reader 来读取;
bin用 DataInputStream来读取。
import sun.net.ftp.FtpClient;public class FtpExample { public static void main(String args[]) throws Exception { FtpClient fc; String host = args[0];
String path = args[1];
String username = args[2];
String password = args[3]; int lastSlash = path.lastIndexOf('/');
String filename = path.substring(lastSlash+1);
String directory = path.substring(0,lastSlash); FtpClient client = new FtpClient(host);
client.login(username, password);
client.binary();
client.cd(directory); InputStream is = client.get(filename);
BufferedInputStream bis = new BufferedInputStream(is); OutputStream os = new FileOutputStream(filename);
BufferedOutputStream bos = new BufferedOutputStream(os); byte[] buffer = new byte[1024];
int readCount; System.out.println("Getting: " + filename);
while( (readCount = bis.read(buffer)) > 0) {
bos.write(buffer, 0, readCount);
}
bos.close();
// client.closeServer();
}
}