为什么代码按照视频抄的,但是复制不了图片,复制的图片几百M ,打不开,求解析
import java.io.*;
import java.net.*;
class PicClient
{
public static void main(String[] args) throws Exception
{
Socket s = new Socket("192.168.0.100", 10008);
FileInputStream fis = new FileInputStream
("D:\\班服图案\\44.bmp");
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();
}
}
class PicServer
{
public static void main(String[] args) throws Exception
{
ServerSocket ss = new ServerSocket(10008);
Socket s = ss.accept();
System.out.println(s.getInetAddress().getHostAddress()+"....connected");
InputStream in = s.getInputStream();
FileOutputStream fos = new FileOutputStream("server.bmp");
byte[] buf = new byte[1024];
int len = 0;
while ((len=in.read())!=-1)
{
fos.write(buf,0,len);
}
OutputStream out = s.getOutputStream();
out.write("上传成功".getBytes());
fos.close();
s.close();
ss.close();
}
}
//为什么图片复制不成功,复制出来的图片几百M |