Reading an image from a file

suggest change
import java.awt.Image;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;

...

try {
    Image img = ImageIO.read(new File("~/Desktop/cat.png"));
} catch (IOException e) {
    e.printStackTrace();
}

A File built from "~/Desktop/cat.png" does not expand ~; that character is a literal path segment.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents