文件传输 我觉得是你的输入输出流使用优点混乱,程序逻辑应该没有问题,dataoutputstream是一个数据过滤流,适合于传输基本数据类型和一些特定数据类型。网络传输过程中,如果不知道具体数据类型,最好使用原始字符流,你可以换做其他一些字符流试试,注意各种类的write和read方法的返回值 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 有谁知道怎么才能实现文件的传输,可否用FileInputStream in=new FileInputStream(file);DataOutputStream out=new DataOutputStream(new BufferedOutputstream(connect.getOutputStream(new FileInputStream(file))));其中connect是一个socket 发送端: DataInputStream fs = new DataInputStream(new FileInputStream(filename)); OutputStream out=connection.getOutputStream(); int len=0; byte[] c_write=new byte[1024]; int current=0; while((len=fs.read(c_write))>0){ out.write(c_write,0,len); }接收端: InputStream br_socket = connection.getInputStream(); DataOutputStream out_file=new DataOutputStream (new FileOutputStream(filename)); int y = 0; byte f[] = new byte[1024]; while (y=br_socket.read(f))!=-1){ out_file.write(f, 0, y); } 现在能收得到吗?在什么位置有Exception吗?“数组可否用vecket代替,inputstream不能用inputstream.read(vecket)”,vecket是什么?y=br_socket.read(f),读入字节到f中,同时得到字节长度 java动态代理 关于数据库编程的一些问题? Java书 我这个为什么报null 的错啊? 请问写一个类加分号与不加分号有什么区别是? sql语句问题。 两个小问题 请问JAVA的缺点有那些? Java中如何自己封装一个方法实现两个数的交换 javaWeb没有学好会影响框架的学习吗? 学习JAVA先看什么书啊 用Java开发的软件安装程序通常用什么制作?哪里能下载?最好能有使用说明。如果能用,分可以再给。
DataOutputStream out=new DataOutputStream(new BufferedOutputstream(connect.getOutputStream(new FileInputStream(file))));
其中connect是一个socket
DataInputStream fs = new DataInputStream(new FileInputStream(filename));
OutputStream out=connection.getOutputStream(); int len=0;
byte[] c_write=new byte[1024];
int current=0; while((len=fs.read(c_write))>0){
out.write(c_write,0,len);
}
接收端:
InputStream br_socket = connection.getInputStream();
DataOutputStream out_file=new DataOutputStream
(new FileOutputStream(filename));
int y = 0;
byte f[] = new byte[1024]; while (y=br_socket.read(f))!=-1){
out_file.write(f, 0, y);
}