3 Replies - 1739 Views - Last Post: 02 December 2011 - 05:59 PM Rate Topic: ***-- 2 Votes

#1 harrys1307  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 02-December 11

java.io.FileNotFoundException: The system cannot find the file specifi

Posted 02 December 2011 - 03:10 AM

when i try to read a file from my local machine, i can able to read the file. but when i try to read the file form some other machine, i ma getting the error

ex:
In my localhost i have tomcat server. in my application, i am clicking a browse button and selecting a file. when i click upload..file gets uploaded
but the same process when i try to access from some other machine, i am getting error as" java.io.FileNotFoundException: The system cannot find the file specified". can anyone give solution

in addition to my previous explanation, i think so,when i hit from some other machine, it is searching in my localhost, instead of searching in respective machine.

Is This A Good Question/Topic? 0
  • +

Replies To: java.io.FileNotFoundException: The system cannot find the file specifi

#2 EPTRemain  Icon User is offline

  • D.I.C Head

Reputation: 16
  • View blog
  • Posts: 81
  • Joined: 25-May 11

Re: java.io.FileNotFoundException: The system cannot find the file specifi

Posted 02 December 2011 - 05:31 AM

Your stream is not finding the file that's why you are getting that exception. Are you handling it properly? Post your code.

You could test the existance of your file using the exists() method.

This post has been edited by EPTRemain: 02 December 2011 - 05:33 AM

Was This Post Helpful? 0
  • +
  • -

#3 harrys1307  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 02-December 11

Re: java.io.FileNotFoundException: The system cannot find the file specifi

Posted 02 December 2011 - 05:56 AM

public static String getFileContent(File file) throws IOException {
             FileReader in = new FileReader(file);
             StringWriter w = new StringWriter();
             char buffer[] = new char[2048];
             int n = 0;
             while ((n = in.read(buffer)) != -1) {
                 w.write(buffer, 0, n);
             }
             w.flush();
             in.close();
             return w.toString();
         }


i ma passing the file path to this method to read the file

This post has been edited by smohd: 02 December 2011 - 06:02 PM
Reason for edit:: Code tags added. Please use [code] tags when posting codes

Was This Post Helpful? 0
  • +
  • -

#4 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8324
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: java.io.FileNotFoundException: The system cannot find the file specifi

Posted 02 December 2011 - 05:59 PM

so follow EPTRemain suggestion and at the beginning of your getFileContent() check if file.exist()

And I am curious to see what you pass as argument to that method :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1