日期:2014-05-20  浏览次数:20864 次

请教一下,在线等,FileWriter为什么不能写入文件?
建立了一个空文件,

print上有输出

但是就是写不进去文件,为什么?

Java code


import java.io.*;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;



public class TestEmail {
    public static int i = 0;

    public static void main(String[] args) throws IOException{
        
        FileReader fr = new FileReader("c://hello.txt");
        BufferedReader br = new BufferedReader(fr);
        String line = "";
        while((line = br.readLine()) != null){
            email(line);
        }
        fr.close();
        br.close();
        System.out.print("i == " + i);
        
    }
    public static void email(String s) throws IOException{
        FileWriter fw = new FileWriter("c://hello2.txt");
//        BufferedWriter bw = new BufferedWriter(fw);
        String str = "";
        Pattern p = Pattern.compile("\\w*+\\@\\w*\\.[\\w]*");
        Matcher m = p.matcher(s);        
        if(m.find()){
            ++i;
            str = m.group();
            System.out.println(str);
            fw.write(str);
        }
      }
    }





------解决方案--------------------
fw.flush;
fw.close;