我正在尝试将图片加载到JPanel上。我将图像定义为:
Image image = ImageIO.read(new File("~/Desktop/Example.png"));
此行返回以下错误:
Exception in thread "main" javax.imageio.IIOException: Can't read input file!
at javax.imageio.ImageIO.read(ImageIO.java:1301)
at Background.<init>(Background.java:16)
(这是我的代码第16行)
答案 0 :(得分:7)
波形符~
由shell扩展,因此需要替换为在Java中使用。你可以做到
Image image =
ImageIO.read(new File(System.getProperty("user.home") + "/Desktop/Example.png"));