本帖最后由 未发光的金子 于 2014-4-25 12:01 编辑
请问 毕老师的这个tcp多线程传图片程序里 我要是想传任意类型的文件要怎么做?
- Socket s = new Socket("10.12.39.27",10007);
- FileInputStream fis = new FileInputStream(file);
- OutputStream out = s.getOutputStream();
- byte[] buf = new byte[1024];
- int len = 0;
- while((len=fis.read(buf))!=-1)
- {
- out.write(buf,0,len);
- }
- //告诉服务端数据已写完
- s.shutdownOutput();
- InputStream in = s.getInputStream();
- byte[] bufIn = new byte[1024];
- int num = in.read(bufIn);
- System.out.println(new String(bufIn,0,num));
- fis.close();
- s.close();
复制代码 |
|