我写了这段代码,它应该将文件名为 "abc.txt" 的文件中的所有字符替换为星号。但是当我运行这段代码时,它只是删除了文件中的所有内容。请有人帮我找出问题在哪里。谢谢。
import java.io.*;
import java.util.*;
class Virus{
public static void main(String[] args) throws Exception{
File f = new File("abc.txt");
FileReader fr = new FileReader(f);
FileWriter fw = new FileWriter(f);
int count = 0;
while(fr.read()!=-1){
count++;
}
while(count-->0){
fw.write('*');
}
fw.flush();
fr.close();
fw.close();
}
}