• Post Reply Bookmark Topic Watch Topic
  • New Topic

jar input txt file  RSS feed

 
oliver flaviano
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hai
Try this
FileInputStream is = Class.forName("Your class Name ex: com.FileReader").getResourceAsStream("/"+ "filename.txt");
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!