Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- import java.net.ServerSocket;
- import java.net.Socket;
- public class Main{
- public static void main(String[] args) {
- My my=new My();
- my.setVisible(true);
- int a=0,size=0;
- try {
- ServerSocket serverSocket=new ServerSocket(8888);
- Socket socket=serverSocket.accept();
- InputStream inputStream=socket.getInputStream();
- OutputStream outputStream=socket.getOutputStream();
- while (true){
- if ((size=inputStream.available())!=0) {
- byte buf[] = new byte[size+100];
- inputStream.read(buf);
- File file = new File("Files/asd"+a+".txt");
- FileOutputStream fileOutputStream = new FileOutputStream(file);
- fileOutputStream.write(buf);
- fileOutputStream.close();
- my.jLabel.setText(String.valueOf((++a) + " " + socket+" "+size));
- }
- }
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement