title: java socket file transfer output path
body: <p>I'm working on a java project that transfers files between server and client and I've managed to send a file to a desired output location, but the only problem is I have to include the full file name in the output path to save it successfully. My program runs in this way:</p>
  
  <p>First it gets the path of the file to be transferred as input to the console, and then it gets the output path, again as an input to the console.</p>
  
  <p>here are the codes of corresponding file name import and exports(I think the problem is somewhere here and posting this part will be sufficed)</p>
  
  <p><strong>Server Side</strong></p>
  
  <pre><code>....
  String in_filePath = null;
  System.out.print("enter the file name: ");
  in_filePath = sc.nextLine();
  File myFile = new File( in_filePath );
  System.out.println("The file chosen is being sent...");
  byte[] mybytearray = new byte[(int) myFile.length()];
  FileInputStream fis = null;
  
         try {
                 fis = new FileInputStream(myFile);
                 sc.close();
             } catch (FileNotFoundException ex) {
                 ex.printStackTrace();
             }
  </code></pre>
  
  <p><strong>Client Side</strong></p>
  
  <pre><code>.....
  int bufferSize = clientSocket.getReceiveBufferSize();
  is = clientSocket.getInputStream();
  DataInputStream clientdata = new DataInputStream(is);
  String fileName = clientdata.readUTF();
  System.out.println("file to be transferred is: " + fileName );
  System.out.print("file output path: ");
  String out_filePath;
  out_filePath = sc.nextLine();
  File file = new File( out_filePath );
  fos = new FileOutputStream( file );
  bos = new BufferedOutputStream(fos);
  bytesRead = is.read(aByte, 0, aByte.length);
       do {
              baos.write(aByte);
              bytesRead = is.read(aByte);
          } while (bytesRead != -1);
  bos.write(baos.toByteArray());
  System.out.println(fileName + " transferred successfully");
  </code></pre>
  
  <p>At first I haven't included the output path in my program; as expected the output path was the root project folder and it was working great as it was reading the filename and sending the file with the same name without problems. But when I implemented the output path query, the output paths I choose like "C:\" or "C:\blabla\" gives me the exception as I stated above. Moreover giving the output path as "C:\image.jpg" or "blablabla\image.jpg" works perfectly well(assuming the name of the file to be copied as image.jpg) can it be a problem with reading the file name? any help would be appreciated</p>
  
  <p>edit: now I'm receiving a socket write error if I had given "c:\" (or any kind of paths like that) as output path, yet it still works well if the output path is given like "c:\image.jpg"</p>