• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to read a .txt file within a .jar  RSS feed

 
Hans Williams
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
Im developing a business utility that needs to read 2 .txt files (26k each). The classes will be packaged in a .jar file and i want to put the txt files into those jars.
First i developed the functionality reading the files outside the .jar, from an absolute path but everytime we take the .jar to a new server i need to change that path, that's why i would like to know if i can read a file inside the .jar and how can i do it.
thanks in advance

kind regards
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Welcome to JavaRanch!

Yes, you can do this easily. Use the methodjava.lang.Class.getResource() to open a stream on the file.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!