To Save Image By Using Image

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
/*
* @Author : Spice
* You Should give a File path to save
*/
public class SaveImage {
public static String stt;

public static void saveImage(File fileToSave )
{

// String stt=ImagePanel.pathname;
FileInputStream from = null;
FileOutputStream to = null;
try {
from = new FileInputStream(stt);
to = new FileOutputStream(fileToSave);
byte[] buffer = new byte[4096];
int bytesRead;
while ((bytesRead = from.read(buffer)) != -1)
to.write(buffer, 0, bytesRead);// write
to.close();
}catch(NullPointerException e){
e.printStackTrace();
}catch(Exception e){
e.printStackTrace();
}
}

}

No comments:

Post a Comment