当前所在位置:珠峰网资料 >> 计算机 >> 计算机等级考试 >> 正文
2015年计算机二级考试JAVA知识点整理(39)
发布时间:2010/12/14 15:00:17 来源:城市学习网 编辑:ziteng
  1.3.5 文件流的建立
  File f=new File("temp.txt");
  FileInputStream in=new FileInputStream(f);
  FileOutputStream out=new FileOutputStream(f);
  例子:文件拷贝
  import java.io.*;
  public class Copy{
  public static void main(String args[]){
  FileInputStream fis=null;
  FileOutputStream fos=null;
  try{
  fis=new FileInputStream("c2.gif");
  fos=new FileOutputStream("c2_copy.gif");
  int c;
  while((c=fis.read()) != -1)
  fos.write(c);
  }catch(Exception e){
  e.printStackTrace();
  }finally{
  if(fis != null) try{ fis.close(); }catch(Exception e){ e.printStackTrace(); }
  if(fos!= null) try{ fos.close(); }catch(Exception e){ e.printStackTrace(); }
  }
  }
  }
广告合作:400-664-0084 全国热线:400-664-0084
Copyright 2010 - 2017 www.my8848.com 珠峰网 粤ICP备15066211号
珠峰网 版权所有 All Rights Reserved