黑马唐贤来 发表于 2013-1-21 22:57
同学,我也试过了,能读出来啊,没有一点问题,你在试试我的?
图片是我打印出来的结果
下面是全部程序- import java.io.*;
- class TestFile
- {
- public static void main(String[] args)
- {
- writeFile();
- readFile();
- }
- public static void writeFile()
- {
- FileWriter fw=null;
- try
- {
- fw=new FileWriter("demo.txt",true);
- fw.write("nihao\rkjdkalkkl");
- }
- catch (IOException e)
- {
- System.out.println(e.toString());
- }
- finally{
- try
- {
- if(fw!=null)
- fw.close();
- }
- catch (IOException e)
- {
- System.out.println(e.toString());
- }
-
- }
- }
- public static void readFile()
- {
- FileReader fr=null;
- try
- {
- fr=new FileReader("demo.txt");
- char[] buf=new char[1024];
- int num=0;
- while((num=fr.read(buf))!=-1)
- {
-
- System.out.println(new String(buf,0,num));
- }
- }
- catch (IOException e)
- {
- }
- finally{
- try
- {
- if(fr!=null)
- fr.close();
- }
- catch (IOException e)
- {
- }
-
- }
- }
- }
复制代码 |
|