简单的字节流

来源:互联网 发布:矩阵a 1 编辑:程序博客网 时间:2024/05/22 15:37

//从一个txt文件写到另一个文件

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

public class TestByteStream {

 public static void main(String[] args) {
  // TODO Auto-generated method stub
  FileInputStream in=null;
  FileOutputStream out=null;
  String path="D://JavaProject//练习//src//com//";
  try{
   in=new FileInputStream(path+"IO文本.txt");
   out=new FileOutputStream(path+"IO文本复件.txt");
   int c;
   while((c=in.read())!=-1){
    out.write(c);
   }
  }catch(FileNotFoundException e){
   e.printStackTrace();
  }catch(IOException e){
   e.printStackTrace();
  }finally{
   try {
    if(in!=null)
    in.close();
    if(out!=null)
     out.close();
   }catch (IOException e){
    e.printStackTrace();
   }
  }
 }

}
 

原创粉丝点击