Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

path/directory of program  RSS feed

 
martin chile
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
i need to know how i can retrieve the full path the program has been started form.
i'm searching for something like "getmyroot()" so that i can open a file i'm distributing with the program (just "file.txt" is not enough).
thanks for helping,
yours, martin
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I answered this already, but I don't know if it was in another forum, or if a UBB error threw my answer out. Excuse me if I'm repeating myself.
Use Class.getResourceAsStream() to open a file that's "near" a .class file. For example, if Foo.class and data.txt are supposed to be in the same directory (either in a JAR file, or separately on disk) then
InputStream is = Foo.class.getResourceAsStream("data.txt");
gives you a stream through which you can read data.txt.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!