• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Tim Cooke
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
Saloon Keepers:
  • Piet Souris
Bartenders:

Read Text File Using Relative Path.

 
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Marshal
Posts: 82459
594
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic