Here is what you're actually doing within your while
loop (read the comments):
// iterating over the items of your own static array (without fast enumeration)
for (int i = 0; i < symbolsAndLetters.length; i++) {
// initializing a new String and assigning it the value of your array
// that is currently indexed in your for-loop
String str = symbolsAndLetters[i];
// replacing the String's content by replacing its value
// (1st parameter, the "str" value itself)
// with an empty String
str = str.replace(str, "");
}
This accomplishes strictly nothing.
Here's what you want to do.
- Assign your writer to a new file. You can always replace the original afterwards.
- Or better, just use a
StringBuilder
and replace the contents of the original with thetoString
representation of theStringBuilder
once the original reader is closed. - Remove the useless "characters"
String
array Use regex as such:
// your outer loop iterating over each line of your input file while ((line = reader.readLine()) != null) { // writing a new String representing the line read from the // original, // but replacing each of its alphabetic characters (through regex) // with an empty String writer.write(line.replaceAll("\\p{Alpha}", "")); }