A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

© fmi110 高级黑马   /  2015-9-7 23:44  /  165 人查看  /  0 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

a
  1. package InOutDemo;

  2. import java.io.FileInputStream;
  3. import java.io.FileOutputStream;
  4. import java.io.IOException;

  5. public class InOutDemo2 {

  6.         /**
  7.          * @param args
  8.          */
  9.         public static void main(String[] args) {
  10.                 // TODO Auto-generated method stub
  11.                 //定义输出流和输入流并初始化
  12.                 FileOutputStream fos = null;
  13.                 FileInputStream fin = null;
  14.                 try{
  15.                         fos = new FileOutputStream("E:\\copy.txt",true);
  16.                         fin = new FileInputStream("Demo1.java");
  17.                         //读取文件
  18.                         int by = 0;
  19.                         while((by = fin.read())!= -1){
  20.                                 fos.write(by);
  21.                         }
  22.                         System.out.println("copy done!!");
  23.                 }
  24.                 catch(IOException e){
  25.                         e.printStackTrace();
  26.                 }
  27.                 finally{
  28.                         if(fin != null){
  29.                                 try {
  30.                                         fin.close();
  31.                                 } catch (IOException e) {
  32.                                         // TODO Auto-generated catch block
  33.                                         e.printStackTrace();
  34.                                 }
  35.                         }
  36.                         if(fos != null){
  37.                                 try {
  38.                                         fos.close();
  39.                                 } catch (IOException e) {
  40.                                         // TODO Auto-generated catch block
  41.                                         e.printStackTrace();
  42.                                 }
  43.                         }
  44.                 }
  45.         }

  46. }
复制代码


0 个回复

您需要登录后才可以回帖 登录 | 加入黑马