第1个回答 2012-06-11
参看代码:
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
public class SaveImage {
/**
* 百度知道回答 sf156454的提问
* @param args
* @throws Exception
*/
public static void main(String[] args) throws Exception {
saveImageAsOtherDir("D:" + File.separator + "xx.jpg", "D:" + File.separator + "test.jpg");
}
private static void saveImageAsOtherDir(String imageDir, String saveDir) throws Exception {
FileInputStream fis = new FileInputStream(new File(imageDir));
FileOutputStream fos = new FileOutputStream(new File(saveDir));
byte[] b = new byte[1];
while(fis.read(b) != -1) {
fos.write(b);
fos.flush();
}
fis.close();
fos.close();
}
}本回答被网友采纳