码迷,mamicode.com
首页 > 编程语言 > 详细

java I/O

时间:2016-06-19 01:14:57      阅读:242      评论:0      收藏:0      [点我收藏+]

标签:

1、输入流、输出流

2、字节流、字符流

3、节点流、处理流

字节流:InputStream OutputStream

字节流:小数据读写;字符流:大文件读写;

try{
  FileInputStream fis = new FileInputStream("from.txt");
  FileOutputStream fos = new FileOutputStream("to.txt");

  byte[] buffer = new byte[1024];

  while(true){
    int temp = fis.read(buffer,0,buffer.length);
    if(temp == -1){
      break;
    }
    fos.write(buffer,0,temp);
}
}catch(Exception e){
  System.out.println(e);
}finally{
  try{
    fis.close();
    fos.close();
  }
  catch(Exception e){
    System.out.println(e);
  }
}

 处理流

 

try{
  FileReader fr = new FileReader ("from.txt");
    BufferedReader bf = new BufferedReader(fr );
  FileWriter fw = new FileWriter ("to.txt");
    BufferedWriter bw= new BufferedWriter(fw );

  

  while(true){
    stirng line  = br.readLLine();
    if(line  == null){
      break;
    }
    bw.writeLine();
}
}catch(Exception e){
  System.out.println(e);
}finally{
  try{
    BufferedReader.close();
    BufferedWriter.close();
    FileReader.close();
    FileWriter.close();
  }
  catch(Exception e){
    System.out.println(e);
  }
}

 

java I/O

标签:

原文地址:http://www.cnblogs.com/zengneng/p/5597235.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!