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 明天继续看书