import java.io.*;
import java.net.*;
class PicClient{
public static void main(String[] args) throws Exception{
Socket s = new Socket("192.168.1.121",10001);
FileInputStream fis = new FileInputStream("f:\\chat.png");
byte[] buf = new byte[1024];
int len = 0;
OutputStream os = s.getOutputStream();
while((len=fis.read(buf))!=-1){
os.write(buf,0,len);
}
s.shutdownInput();
InputStream is = s.getInputStream();
byte[] bufIn = new byte[1024];
int len2 = is.read(bufIn);
System.out.println(new String(bufIn,0,len2));
fis.close();
os.close();
is.close();
}
}
class PicServer{
public static void main(String[] args)throws Exception{
ServerSocket ss = new ServerSocket(10001);
Socket s = ss.accept();
InputStream is = s.getInputStream();
byte[] buf = new byte[1024];
FileOutputStream fos = new FileOutputStream("2.jpg");
int len = 0;
while((len=is.read(buf))!=-1){
fos.write(buf,0,len);
}
PrintWriter pw = new PrintWriter(s.getOutputStream());
pw.println("上传成功".getBytes());
is.close();
fos.close();
pw.close();
}
}
上传图片的时候遇到这个问题,不知道怎么回事
|
|