- import java.io.*;
- import java.net.*;
- class UpClient
- {
- public static void main(String [] args) throws Exception
- {
- Socket s = new Socket("192.168.1.9",10012);
- BufferedReader bufr =
- new BufferedReader(new FileReader("c:\\a.txt"));
-
- PrintWriter pw =
- new PrintWriter(s.getOutputStream(),true);
-
- String line = null;
-
- while((line = bufr.readLine())!=null){
- pw.println(line);
- }
- s.shutdownOutput();
-
- BufferedReader bufin =
- new BufferedReader(new InputStreamReader(s.getInputStream()));
- String str = null;
- str = bufin.readLine();
- System.out.println(str);
- bufr.close();
- s.close();
-
-
- }
- }
- class UpServer
- {
- public static void main(String [] args) throws Exception
- {
- ServerSocket ss = new ServerSocket(10012);
- Socket s = ss.accept();
-
- String ip = s.getInetAddress().getHostAddress();
-
- System.out.println(ip+"......connected");
-
- BufferedReader bufr =
- new BufferedReader(new InputStreamReader(s.getInputStream()));
-
- BufferedWriter bufw =
- new BufferedWriter(new FileWriter("c:\\bbb.txt"));
-
- String line = null;
-
- while((line = bufr.readLine())!=null){
-
- bufw.write(line);
- bufw.newLine();
- bufw.flush();
- }
- PrintWriter pw =
- new PrintWriter(s.getOutputStream(),true);
- pw.println("上传成功");
- bufw.close();
- s.close();
-
- ss.close();
-
- }
- }
复制代码
看过好长时间了,重新敲感觉不一样了 |
|