aspose file tools*
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


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Read Text File Using Relative Path." Watch "Read Text File Using Relative Path." New topic
Author

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
Sheriff

Joined: Oct 13, 2005
Posts: 38412
    
  23
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 java.io.File 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.
 
Consider Paul's rocket mass heater.
 
subject: Read Text File Using Relative Path.