import java.io.*;
import java.net.*;
class PicClient
{
public static void main(String[] args)throws Exception
{
Socket s=new Socket("192.168.1.100",8001);
BufferedInputStream fis=new BufferedInputStream(new FileInputStream("何洁 陈楚生 - 经过.mp3"));
BufferedOutputStream os=new BufferedOutputStream(s.getOutputStream());
int len=0;
while((len=fis.read())!=-1)
{
os.write(len);
}
s.shutdownOutput();
InputStream is=s.getInputStream();
byte[] buf=new byte[1024];
len=is.read(buf);
System.out.println(new String(buf,0,len));
s.close();
}
}
class PicServer
{
public static void main(String[] args)throws Exception
{
ServerSocket ss=new ServerSocket(8001);
Socket s=ss.accept();
System.out.println(s.getInetAddress().getHostAddress());
BufferedInputStream is=new BufferedInputStream(s.getInputStream());
BufferedOutputStream fos=new BufferedOutputStream(new FileOutputStream("1.mp3"));
int len=0;
while((len=is.read())!=-1)
{
fos.write(len);
}
OutputStream os=s.getOutputStream();
os.write("上传成功!".getBytes());
s.close();
ss.close();
}
}
原MP3是3,906,143 字节,传送完后的MP3是3,891,200 字节,数据在那里丢失的啊? |