dimanche 29 mars 2015

Using write method to save a picture file in Java



I need to save a picture object into the working directory with a specific file name using the write method. Here's my code:


public void storePhotos(String directory){



for(int i = 0; i < labelledPhotos.length; i++){
Picture currentPhoto = new Picture(labelledPhotos[i].getLabelledPhoto());

String fileName = directory + "/" + labelledPhotos[i].getYear() + "_" + labelledPhotos[i].getCategory() + "_" + labelledPhotos[i].getId() + ".jpg";
currentPhoto.write(fileName);

}


The user is suppose to input the director as the parameter and I need to save the image to the directory. For some reason the write method isn't saving it. If I hard code in the directory into the write parameter like:


currentPhoto.write("pic.jpg");


then the photo gets saved into directory. So I know its something wrong with the String fileName and how it gets passed into the write method, but I'm not sure what. Any help would be greatly appreciated.




Aucun commentaire:

Enregistrer un commentaire