Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

FileNotFoundException though the File is in Same Folder , UNIX  RSS feed

 
sshivade
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
To log the visitors of my site I have written a class which picks up the users machines Hostname and IpAddress and logs it to a file called visitors.log. Locally when I run this class it works fine but when I have uploaded this class on site it gives me FileNotFoundException error.
This file is not a Directory, it exists in the same folder where the class is , this file has full permissions as OS is UNIX.
I would really appreciate it if somebody could suggest me the reason.
Thanks
Sanjay
------------------
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you haven't already done so, create a File object using thw path to the file you are trying to find. Then do
<code><pre> System.out.println("Looking for file " + file.getAbsolutePath());</pre></code>
Just before trying to open the file. This will tell you exactly where the program is looking for your file. Based on this, you can either modify the filename / path which the program looks for, change the directory from which you execute the program on the client maching (which should be the working directory from which all relative path names are interpreted), or you can move the file on the client machine to be in the expected location. Good luck.
 
sshivade
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your suggestion..Jim.
The solution did'nt work.. Here is my original code.
The following class has a method, "GetToken" , which is supposed to open a file and return the information in the form of tokens . Calling class has to just display the tokens. Both the class file and the file (jobs.txt) are in the same folder.
import java.io.*;
class GetToken
{
String GetToken()
{
try
{
FileReader filereader = new FileReader("jobs.txt");
StreamTokenizer stk = new StreamTokenizer(filereader);
String instring;
while (stk.nextToken() != StreamTokenizer.TT_EOF)
{
if (stk.ttype == StreamTokenizer.TT_WORD)
{
//System.out.println(stk.sval);
return stk.sval;
}
}
}
catch (IOException e)
{
//System.out.println(e);
return "IOException :"+ e;
}
return "";
}
}

Sanjay.
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ummm... a command that says "System.out.println(...)" isn't intended to be a complete solution - it's a diagnostic tool. Put the line in your program, run it, and look at the output. Compare the file path it tells you to the actual class path to the file. This tells you the difference between where your program is looking, and where the file really is. From this you may well be able to figure out what's going on. If not, tell us what the print statement printed, and what is the actual class path to your file.
 
sshivade
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Jim,
Thanks a lot..
I tested the path using getAbsoluteFilePath function. It showed me the path where it is looking for the named file. It showed me an unexpected path, which I could have never thought of, as the OS was UNIX..It was looking the file in // root.. I used the same path and then added //usr48/...../jobs.txt..and could proceed further .............Once again thanks a lot.
Now, the issue is that , I am trying to get the host name using req.getRemoteHost() function, which is supposed to return the clients host name. But it returns blank...inspite of the client having the host name...Can u tell me the reason behind this? I am desperately trying to get this.
Thanking you in advance.
Sanjay.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!