• 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 all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Liutauras Vilda
  • Paul Clapham
  • Bear Bibeault
  • Jeanne Boyarsky
  • Ron McLeod
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Jj Roberts
  • Stephan van Hulst
  • Carey Brown
  • salvin francis
  • Scott Selikoff
  • fred rosenberger

path/directory of program

Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
author and iconoclast
Posts: 24203
Mac OS X Eclipse IDE Chrome
  • 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.
Crusading Chameleon likes the size of this ad:
Thread Boost feature
    Bookmark Topic Watch Topic
  • New Topic