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
To read some files from inside jar you should do:
getClass().getResourceAsStream("path/to/file");
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.