Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Read Text File Using Relative Path.

 
Chandra Mohan
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Campbell Ritchie
Sheriff
Posts: 48652
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic