保存此图片时:
用这种方法:
private final static Path ROOT_PATH = Paths.getPath("C:/images");
private static void saveImageFromWebSimple(final String url) {
URL u = null;
try {
u = new URL(url);
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String file = url.substring(url.indexOf("//") + 2);
Path filePath = ROOT_PATH.resolve(file);
try {
Files.createDirectories(filePath.getParent());
BufferedImage img = ImageIO.read(u);
ImageIO.write(img, "jpg", filePath.toFile());
} catch (IOException e) {
e.printStackTrace();
}
}
这是我的结果:
虽然所有照片都不会发生这种情况。
你能告诉我为什么吗?