Renee
Renee

Reputation: 1

Java Export - Text Files

I tried to export a Java program from Eclipse to a .jar file, but I came across a problem. It ran fine, but for some reason it didn't find the text files it was supposed to get data from. If anyone could help with this, I would be very grateful.

Upvotes: 0

Views: 1306

Answers (3)

moritz
moritz

Reputation: 2478

I guess we need some more information to help you solve this problem. Where are your text files located while debugging and developing your code? Make sure that they are accessible from the path you are running the jar in.

Upvotes: 0

bmargulies
bmargulies

Reputation: 100042

If your program depends on internal text files, put them in classpath and package them in the jar. Find them with the Class.getResourceAsStream.

Upvotes: 0

Brian Agnew
Brian Agnew

Reputation: 272267

Where are these text files ? If they're packaged within your .jar file, I would expect to be able to find them within the class hierarchy using ClassLoader.getResourceAsStream(), specifying the complete path relative to the classloader base.

Upvotes: 3

Related Questions