Reading a file from a relative path
I know this question has been asked 1000 times before. I've tried all solutions ( How do I read a file from a relative path in a Java project? Java.io.File can't find the path specified) doesn't work either) however none seem to work.
I am trying to read an image file by providing a relative path like this:
BufferedImage image;
image = fm.readMap("..\\..\\resources\\5x5.png");
Reading:
public BufferedImage readMap(String path)
{
BufferedImage img = null;
try{
img = ImageIO.read(new File(path));
}
catch (IOException e){
System.out.println("Image not found.");
e.printStackTrace
}
return img;
}
code location:
parent -> src -> externalsourcemanagement -> TestMapAnalysis.java
image location: parent -> resources -> 5x5.png
Thanks in advance!
+3
source to share