Advertisement
Guest User

Untitled

a guest
Nov 12th, 2014
302
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.10 KB | None | 0 0
  1. import java.io.*;
  2. import java.net.ServerSocket;
  3. import java.net.Socket;
  4.  
  5. public class Main{
  6.     public static void main(String[] args) {
  7.         My my=new My();
  8.         my.setVisible(true);
  9.         int a=0,size=0;
  10.  
  11.         try {
  12.             ServerSocket serverSocket=new ServerSocket(8888);
  13.             Socket socket=serverSocket.accept();
  14.             InputStream inputStream=socket.getInputStream();
  15.             OutputStream outputStream=socket.getOutputStream();
  16.  
  17.             while (true){
  18.                 if ((size=inputStream.available())!=0) {
  19.                     byte buf[] = new byte[size+100];
  20.                     inputStream.read(buf);
  21.                     File file = new File("Files/asd"+a+".txt");
  22.                     FileOutputStream fileOutputStream = new FileOutputStream(file);
  23.                     fileOutputStream.write(buf);
  24.                     fileOutputStream.close();
  25.                     my.jLabel.setText(String.valueOf((++a) + "     " + socket+"   "+size));
  26.                 }
  27.             }
  28.         } catch (IOException e) {
  29.             e.printStackTrace();
  30.         }
  31.     }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement