Change /
for
if you are using windows.
A more cross-platform approach would be substitute
C:
for File.listRoots()[0]
and every /
for File.separator
.
Read more on the File api documentation
EDIT
(I didn't read this line, sorry)
This code was running properly untill i try to read an image from the source package
In order to get a file from inside your jar package, one must use the getClass().getResource()
method.
Example:
application-package:
|-Main.java
|-resources
|-image.jpg
For the above directory structure:
BufferedImage im = ImageIO.read(new File(getClass().getResource("/resources/image.jpg").toURI()));
Would do the trick.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…