The moose likes I/O and Streams and the fly likes jar input txt file Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » I/O and Streams
Reply Bookmark "jar input txt file" Watch "jar input txt file" New topic
Author

jar input txt file

oliver flaviano
Greenhorn

Joined: Mar 10, 2002
Posts: 2
Hi Everyone !
I am a newby in java and experimenting with jars. I have an application reading an input txt file - when i created a jar for it, including the txt file, the jarred application can not seem to find the txt file. When i placed the txt file on the same directory as the jar file ok.
What do i need to do so that the jarred application can see the input txt in the jar file ? Another question, can a txt file in a jar file be used as i/o or just input only ?
Thanks !
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
If you put your text file inside the jar, you'll need the classes from the java.util.jar package to read them.
It's not because your program runs the same, no matter whether your classes come from the class files or from a jar, that any file can be found inside the jar automatically!
The classloader handles the difference between seperate class files and files in a jar, but for the text file you'll have to do it yourself ...
Regards,
G�nther
http://www.javacoding.net
oliver flaviano
Greenhorn

Joined: Mar 10, 2002
Posts: 2
Hi Gunther
Thanks for your help ! After some hours of frustration , i finally found that jarfile is case sensitive and made my application worked.
Ramakrishnan G
Greenhorn

Joined: Mar 15, 2002
Posts: 3
Hai
Try this
FileInputStream is = Class.forName("Your class Name ex: com.FileReader").getResourceAsStream("/"+ "filename.txt");
 
 
subject: jar input txt file
 
Threads others viewed
.jar reading a text file
JFileChooser - To use or not to use
Vector input .txt
Question on images and packages
Problem with the use of external library from a jar archive
IntelliJ Java IDE

cast iron skillet 49er

more from paul wheaton's glorious empire of web junk: cast iron skillet diatomaceous earth rocket mass heater sepp holzer raised garden beds raising chickens lawn care CFL flea control missoula heat permaculture