import java.io.*;public class CopyFile { public static void main(String[] args) { try { File fs = new File("c:\\src.jpg"); FileInputStream fis = new FileInputStream(fs); byte[] b = new byte[(int)fs.length()]; fis.read(b); File fd = new File("c:\\des.jpg"); FileOutputStream fos = new FileOutputStream(fd); fos.write(b); fos.close(); fis.close(); }catch(Exception exp){} } }
byte[] b = new byte[(int)fs.length()]; fis.read(b); --------- 文件不大这样处理没有问题,文件太大的话可以用缓冲 不过图片的话这样处理就ok了byte[] b = new byte[1024]; while(fis.read(b)!=-1){ fos.write(b); }
FileInputStream为源,FileOutputStream为目的,重新写一个文件就好了
{
public static void main(String[] args)
{
try
{
File fs = new File("c:\\src.jpg");
FileInputStream fis = new FileInputStream(fs);
byte[] b = new byte[(int)fs.length()];
fis.read(b);
File fd = new File("c:\\des.jpg");
FileOutputStream fos = new FileOutputStream(fd);
fos.write(b);
fos.close();
fis.close();
}catch(Exception exp){}
}
}
fis.read(b);
---------
文件不大这样处理没有问题,文件太大的话可以用缓冲
不过图片的话这样处理就ok了byte[] b = new byte[1024];
while(fis.read(b)!=-1){
fos.write(b);
}