没必要看代码
- package SendPhotoServer;
- import java.io.BufferedInputStream;
- import java.io.BufferedOutputStream;
- import java.io.File;
- import java.io.FileInputStream;
- import java.io.PrintStream;
- import java.net.ServerSocket;
- import java.net.Socket;
- public class SendPhotoServer
- {
- public static void main(String[] args) throws Exception
- {
- ServerSocket ss=new ServerSocket(10000,50);
- Socket s=ss.accept();
- BufferedOutputStream bos=new BufferedOutputStream(s.getOutputStream());
- PrintStream ps=new PrintStream(s.getOutputStream(),true);
- int n=1;
- File file=new File("C:\\Users\\WJS\\Desktop\\test1\\27.jpg");
- if(file.exists())
- {
- BufferedInputStream bis=new BufferedInputStream(new FileInputStream(file));
- int tmp=-1;
- while((tmp=bis.read())!=-1)
- {
- bos.write(tmp);
- }
- bis.close();
- bos.flush();
- bos.close();
-
- ps.print("图片上传完毕");
- s.close();
- }
- else
- {
- System.out.println("图片不存在");
- }
- }
- }
复制代码- import java.io.BufferedInputStream;
- import java.io.BufferedOutputStream;
- import java.io.FileOutputStream;
- import java.net.Socket;
- public class SendPhotoClient
- {
- public static void main(String[] args) throws Exception
- {
-
- Socket s=new Socket("127.0.0.1",10000);
- BufferedInputStream bis=new BufferedInputStream(s.getInputStream());
- BufferedOutputStream bos=new BufferedOutputStream(new FileOutputStream("C:\\Users\\WJS\\Desktop\\test2\\1.jpg"));
- int tmp=-1;
- while((tmp=bis.read())!=-1)
- {
- bos.write(tmp);
- }
- bis.close();
- bos.flush();
- bos.close();
-
-
-
-
-
-
- }
- }
复制代码
注意改下路径 |