I am trying to do the above, but each time, I keep getting the following errorjava.io.FileNotFoundException: file:\C:\Users\User\Desktop\Scrap\main\out\production\resources\ProfilePic\xas.png (The filename, directory name, or volume label syntax is incorrect)
Here's the function I used to do this
private URL url = this.getClass().getResource("/ProfilePic");
public final String PICTURE_DIRECTORY = url.toString();
public String createNewPicture (String path, String newPictureName) {
int width = 12;
int height = 12;
BufferedImage bf = null;
File f = null;
String dst = PICTURE_DIRECTORY +"/"+newPictureName+".png";
try{
f = new File("F://a.jpg");
bf = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
bf = ImageIO.read(f);
System.out.println("read file successfully");
} catch (Exception e) {
System.out.println(e.getMessage());
}
try {
dst = PICTURE_DIRECTORY +"/"+newPictureName+".png";
new File (PICTURE_DIRECTORY, newPictureName+".png");
f = new File(dst);
ImageIO.write(bf, "png", f);
//System.out.println("asaas " +dst);
}
catch (Exception e) {
System.out.println(e.getMessage());
}
return dst;
}
Can someone please help me? Spent several hours trying to solve this but stuck. Thanks!
bf = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);You just get rid of it on the next line. Which line is causing the file not found? Also you cannot write to a resource like that. Your PICTURE_DIRECTORY is wrong.ImageIOis great when you want to display or modify images. For copying files, it's simply the wrong solution. UseFiles.copy(...), see the Copying a File or Directory tutorial.