java.io.FileNotFoundException: (The system cannot find the path specified)
14,609
The directory cannot be found. The message is confusing because it talks of "file" but in Java IO, a directory is a File too.
If you run:
File dir = new File(serveradd+"\\IndiraSharing")
System.out.println(dir.exists());
It will print:
false
You could try to create the directory structure:
dir.mkdirs();
Also, check the absolute path is what you are expecting:
System.out.println(dir.getAbsolutePath());
Author by
Admin
Updated on June 04, 2022Comments
-
Admin almost 2 years
I am new to Socket programming. I am trying to write a file on server, but my code throws an exception:
java.io.FileNotFoundException: Welcome-PC\IndiraSharing\hadoop.txt (The system cannot find the path specified)
Here is my code.
Socket s; ServerSocket server = new ServerSocket(5555); String serveradd; serveradd=s.getInetAddress().getHostName(); // System.out.println("Server accepted client"); InputStream input = s.getInputStream(); BufferedReader inReader = new BufferedReader(new InputStreamReader(s.getInputStream())); BufferedWriter outReader = new BufferedWriter(new OutputStreamWriter(s.getOutputStream())); String filename = inReader.readLine(); if ( !filename.equals("") ){ outReader.write("READY\n"); outReader.flush(); } FileOutputStream wr = new FileOutputStream(new File(serveradd+"\\IndiraSharing/" + filename)); byte[] buffer = new byte[s.getReceiveBufferSize()]; int bytesReceived = 0; while((bytesReceived = input.read(buffer))>0) { wr.write(buffer,0,bytesReceived); }
-
ᴇʟᴇvᴀтᴇ over 10 yearsIt wasn't intended to be a solution. It was intended to help you debug by narrowing in on the problem, so you can solve it.