Okay, I'm trying to load a file in Java using this code:
String file = "map.mp";
URL url = this.getClass().getResource(file);
System.out.println("url = " + url);
FileInputStream x = new FileInputStream("" + url);
URL url = this.getClass().getResource("default.png");
System.out.println("url2 = " + this.getClass().getResource("default.png"));
BufferedImage img = ImageIO.read(url);
You're trying to use a url as if it's a filename. It won't be. It'll be something starting with
file://. In other deployment scenarios there may not be an actual file to open at all - it may be within a jar file, for example. You can use
URL.getFile() if you really, really have to - but it's better not to.
getResourceAsStream instead of
getResource() - that gives you an
InputStream directly. Alternatively, keep using
getResource() if you want the URL for something else, but then use
URL.openStream() to get at the data.