public class ImageCopy { /**
* @param args
*/
public static void main(String[] args) {
FileInputStream fio =null;
FileOutputStream fos = null;
try {
fio = new FileInputStream("e:\\s.jpg");
fos = new FileOutputStream("d:\\w.jpg");
byte temp[] = new byte[1024];//缓存
//循环读取
int n=0;//记录实际读取到的字节数,实际读取了几个字节
while((n=fio.read())!=-1){
//输出到指定文件
fos.write(temp);
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally {
try {
fio.close();
fos.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}}输出的这个 w.jpg 有10.8 MB 而原始文件s.jpg 是10.8KB
而且用acdsee打开的时候,图片是啥都没有的,“ 原始数据格式无法识别”。
* @param args
*/
public static void main(String[] args) {
FileInputStream fio =null;
FileOutputStream fos = null;
try {
fio = new FileInputStream("e:\\s.jpg");
fos = new FileOutputStream("d:\\w.jpg");
byte temp[] = new byte[1024];//缓存
//循环读取
int n=0;//记录实际读取到的字节数,实际读取了几个字节
while((n=fio.read())!=-1){
//输出到指定文件
fos.write(temp);
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally {
try {
fio.close();
fos.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}}输出的这个 w.jpg 有10.8 MB 而原始文件s.jpg 是10.8KB
而且用acdsee打开的时候,图片是啥都没有的,“ 原始数据格式无法识别”。
//输出到指定文件
//fos.write(temp);
fos.write(temp, 0, n);
}换成这个OK