本帖最后由 20140829 于 2014-11-17 14:32 编辑
- import java.io.*;
- class CopyPic
- {
- public static void main(String[] args)
- {
- FileOutputStream fos = null;
- FileInputStream fis = null;
- try
- {
- fos = new FileOutputStream("c:\\2.bmp");文件输出
- fis = new FileInputStream("c:\\1.bmp");//文件读取(这里是源文件)
- byte[] buf = new byte[1024];
- int len = 0;
- while((len=fis.read(buf))!=-1)//把读取的(数据)文件存到buf当中
- {
- fos.write(buf,0,len);//输出buf当中存储的(数据)文件。
- }
- }
- catch (IOException e)
- {
- throw new RuntimeException("复制文件失败");
- }
- finally
- {
- try
- {
- if(fis!=null)
- fis.close();
- }
- catch (IOException e)
- {
- throw new RuntimeException("读取关闭失败");
- }
- try
- {
- if(fos!=null)
- fos.close();
- }
- catch (IOException e)
- {
- throw new RuntimeException("写入关闭失败");
- }
- }
- }
- }
复制代码 |