我正在尝试使用此代码从包含随机数字和字母的文本文件中删除所有字母
package textEdit;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
public class RemoveLetters {
public static void readFile(String file) {
try {
FileReader fis = new FileReader(file);
BufferedReader reader = new BufferedReader(fis);
FileWriter writer = new FileWriter(file);
BufferedWriter bwriter = new BufferedWriter(writer);
String line = null;
while ((line = reader.readLine()) != null) {
for (int i = 0; i < symbolsAndLetters.length; i++) {
String str = symbolsAndLetters[i];
str = str.replace(str, "");
}
}
reader.close();
bwriter.close();
} catch (IOException e) {
e.printStackTrace();
}
}
public static String[] symbolsAndLetters = {"A", "B", "C",
"D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N",
"O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y",
"Z", "=","a", "b", "c", "d", "e", "f", "g", "h", "i",
"j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t",
"u", "v", "w", "x", "y", "z",};
/**
* @param args
*/
public static void main(String[] args) {
readFile("c:/users/Kyle/workspace/Learn more java/src/music.txt");
}
}
问题是,它从文件中删除了所有内容,我对用 Java 读写非常陌生,所以谁能帮我弄清楚我做错了什么?