The moose likes Java in General and the fly likes Read Text File Using Relative Path. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Read Text File Using Relative Path." Watch "Read Text File Using Relative Path." New topic

Read Text File Using Relative Path.

Chandra Mohan
Ranch Hand

Joined: Oct 06, 2003
Posts: 62
my question is, How to read the text file which is present in the web-inf folder (web project) using relative path? I can able to read the data using hard code path (Absolute path, c:\temp\...). I am not able to read the file using relative path. My java file is present in com.trave.wss.tfim.sso location and I have used ..//..//..//..//..// while declare text file location. In run time file not found exception is occurred because system not able to locate the text file. I am not sure where i am doing mistake.

Thanks in advance

Thanks and Regards
Chandra Mohan
Campbell Ritchie

Joined: Oct 13, 2005
Posts: 46367
Are you really using ...//...//...// on Windows to define the file location? That won't work; surely you mean C:\\DocumentsAndSettings\\MyDocuments\\MyFolder\\MyFile.txt? Try opening the file with a JFileChooser and then using the getPath() getAbsolutePath() etc methods of find out what to put as the path.
You can presumably only use a relative path if the text file you are looking for is in a subdirectory of the directory you have your Java executables in, so it is probably only possible to get at a file in C:\temp with the absolute or canonical path.
I agree. Here's the link:
subject: Read Text File Using Relative Path.
It's not a secret anymore!