文件数据流操作

来源:互联网 发布:双色球算法必中六红 编辑:程序博客网 时间:2024/05/04 18:07

http://chxkyy.iteye.com/blog/213055


http://blog.csdn.net/swandragon/article/details/4770445


  •     InputStream is = null;  
  •     FileOutputStream fos = null;  
  •   
  •          //这里对is进行赋值,略  
  •           //...  
  •   
  •     // 文件输出流fos  
  •          // openFile()为自定义函数,判断文件是否存在等(略)  
  •     String fileName = "hellostory的日志.doc";  
  •     if(!openFile(fileName)){  
  •         return;  
  •     }  
  •   
  •     try {  
  •         fos = new FileOutputStream(fileName);  
  •     } catch (FileNotFoundException e) {  
  •         e.printStackTrace();  
  •     }  
  •   
  •     int ch = 0;  
  •     try {  
  •         while((ch=is.read()) != -1){  
  •             fos.write(ch);  
  •         }  
  •     } catch (IOException e1) {  
  •         e1.printStackTrace();  
  •     } finally{  
  •         fos.close();  
  •         is.close();  
  •     }
  • BufferedReader   bf   =   new   BufferedReader(
                                                new   InputStreamReader(in));

    String   s   =   null;
    while   ((s=bf.readLine())   !=   null)     System.out.println(s);




  • 原创粉丝点击