getResource returns null for a file that is listed by getResourceAsStream

1 week ago 7
ARTICLE AD BOX

I have resurrected a program written in Java using Eclipse: I last worked on it in 2016. I am now using JaveSE-21, and this code no longer works- the returned URL is null.

String name = "res/images/ifx_micro_red.png"; URL url = ClickImage.class.getClassLoader().getResource(name);

res and res.images appear directly below src in the project tree.

If I add this code just beforehand, the file ifx_micro_red.png is listed.

Scanner scanner = new Scanner(ClickImage.class.getClassLoader().getResourceAsStream("res/images")); while (scanner.hasNextLine()) { System.out.println(scanner.nextLine()); } scanner.close ();

I don't understand how getResourceAsStream can find the file, but getResource cannot.

Read Entire Article