zoukankan      html  css  js  c++  java
  • 【每日日报】第三十一天---文件操作(字节流)

    1 接着看第十二章

    字节流写文件

     1 package File;
     2 import java.io.IOException;
     3 import java.io.FileWriter;
     4 
     5 public class WriteDemo {
     6     public static void main(String[] args) throws IOException{
     7         write();
     8     }
     9     public static void write()throws IOException{
    10             FileWriter fw=new FileWriter("D:/Hello.txt");
    11             fw.write("Hello c艹!");
    12             fw.close();    
    13     }
    14 }

    字节流读文件

     1 package File;
     2 import java.io.IOException;
     3 import java.io.FileReader;
     4 import java.io.Reader;
     5 
     6 public class ReaderDemo {
     7     public static void main(String[] args)throws IOException{
     8         reader();
     9     }
    10     public static void reader()throws IOException{
    11         Reader r=new FileReader("D:/Hello.txt");
    12         char[] buf=new char[1024];
    13         int len=0;
    14         while((len=r.read(buf))!=-1){
    15             String s=new String(buf,0,len);
    16             System.out.println(s);
    17         }
    18         r.close();
    19     }
    20 }
     

    2 没遇到什么问题

    3 明天继续看书

  • 相关阅读:
    Beta 冲刺 (5/7)
    Beta 冲刺 (4/7)
    软件产品案例分析(团队)
    Beta 冲刺 (3/7)
    Beta 冲刺 (2/7)
    Beta 冲刺 (1/7)
    BETA 版冲刺前准备
    个人作业——软件工程实践总结作业
    Beta 答辩总结
    Beta 冲刺 (7/7)
  • 原文地址:https://www.cnblogs.com/linmob/p/13449258.html
Copyright © 2011-2022 走看看