Advertisement
wieruowq

Request file to be received (part of Client.java)

Nov 1st, 2017
242
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.93 KB | None | 0 0
  1.  public void FileRequest() throws FileNotFoundException
  2.  {
  3.         try
  4.         {
  5.             ///
  6.              output2 = new DataOutputStream(socket.getOutputStream());  
  7.              input = new DataInputStream(socket.getInputStream());
  8.              System.out.println("Which file do you want?");
  9.              Scanner scanner = new Scanner(System.in);
  10.              String thisFileName = scanner.nextLine();
  11.              System.out.println("99877");
  12.              if(thisFileName!=null && !thisFileName.isEmpty())
  13.              {
  14.                  System.out.println("666332");
  15.  
  16.                  System.out.println("69683721");
  17.                  output2.writeUTF(thisFileName + "`" + "\n");
  18.                  System.out.println("1234123456666");
  19.                  output2.flush();
  20.                  System.out.println("flushed");
  21.                  long file_size= input.readLong();
  22.                  System.out.println("The file size is: " + file_size);
  23.                  if ( file_size == 0 )
  24.                  {
  25.                      System.out.println("File size is 0");
  26.                  }
  27.                  FileOutputStream file_out= new FileOutputStream( thisFileName );
  28.                  System.out.println("4445555");
  29.                  int number_read;
  30.                  byte[] buffer= new byte[1500];
  31.                  System.out.println("23234");
  32.                  while( (number_read= input.read( buffer)) != -1 )
  33.                  {
  34.                      file_out.write( buffer, 0, number_read );
  35.                      System.out.println("66333");
  36.                  }
  37.                  System.out.println("45531");
  38.                  System.out.println("File " + thisFileName  + " downloaded (" + number_read + " bytes read)");
  39.                  System.out.println("123411");
  40.                     StandardInput();
  41.                 }
  42.                
  43.                  
  44.         }
  45.         catch (IOException e)
  46.         {
  47.             e.printStackTrace();
  48.         }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement