• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Relative path

 
Jessid Leon Velez Gutierrez
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello. I have a question: I am creating an application that want to pack in a jar file. That app uses a couple of plain text files. I want to include thouse 2 files into the jar, but i havent been able to make the app to read them. I dont know how to doit. Perhaps some of you could help me please with that.

Thanks a lot!
 
Stevi Deter
Ranch Hand
Posts: 265
Hibernate Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jessid,

In order to help you, we'll need some more detail.

Where are you putting the file?

What's the code that's trying to open it?

What exception are you seeing (full stack trace helps)?
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24211
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If he doesn't know how to do it, I don't think we need any more detail!

To read files out of the jar a program is packed into, you can't use things like FileReader and FileInputStream. Instead, use the ClassLoader methods that find files along the classpath, like this:

InputStream theFile = getClass().getResourceAsStream("thefile.txt");
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic