0

This is probably a repeated question asked by several people, but i could not understand after searching the answers.

netbeans creates a folder dist after a build operation. I want to place a text file in that folder, the jar file should read the text file.

The target platforms are windows and linux

structure of the folders,

.java file  =  C:\My Documents\NetBeansProjects\Example\src\example
 build folder = C:\My Documents\NetBeansProjects\Example
 build folder contains classes folder. classes folder contains all the class files
 dist folder = C:\My Documents\NetBeansProjects\Example
 dist folder contains the .jar files and i want to place a text file inside this folder

the,

 getClass().getClassLoader().getResource("example.txt");

seems to work only if the path is along with .java files.

Thanks

FirmView
  • 3,130
  • 8
  • 34
  • 50
  • Not too sure if you can directly load it as "example.txt" with no directories, but if you create a folder inside dist - ie "Text files" you can do /textfiles/example.txt – Jimmt Sep 02 '12 at 03:41
  • So you may be able to load it directly, but I'm too lazy to try it... – Jimmt Sep 02 '12 at 03:42

1 Answers1

-1

To read some files from inside jar you should do:

getClass().getResourceAsStream("path/to/file");

See:File loading by getClass().getResource()

Nick
  • 744
  • 6
  • 11