public class Test{
    public static void main(String args[]){
        try{
   File f = new File("stat.txt");
   FileWriter fw = new FileWriter(f);
   fw.write("dasfd");         }catch(IOException e){System.out.println(e.getMessage());}     
    }
}程序是执行了,但是stat.txt里什么也没有,怎么回事呢?

解决方案 »

  1.   

    import java.io.*;
    class Test{
        public static void main(String args[]){
            try{
         File f = new File("stat.txt");
         FileWriter fw = new FileWriter(f);
         fw.write("dasfd");
         fw.close();  //加是这句
             }catch(IOException e){System.out.println(e.getMessage());}     
        }
    }
      

  2.   

    这样肯定不行,你必须有一个FileOutputStream的方法来写入字符到这个文件还可以,建议你好好看看JDK_API文档吧,最好看E文的,写得比较详细
      

  3.   

    不好意思,我就是看了半天JDK_API,e文的
    见鬼了,原来是没CLOSE,真粗心,谢谢各位