Что не так ?
package com.javarush.task.task19.task1909;
import java.io.*;
import java.util.ArrayList;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/*
Замена знаков
*/
public class Solution {
public static void main(String[] args) throws IOException {
BufferedReader buf = new BufferedReader(new InputStreamReader(System.in));
String x = buf.readLine();
String z = buf.readLine();
buf.close();
BufferedReader rd = new BufferedReader(new FileReader(x));
BufferedWriter wr = new BufferedWriter(new FileWriter(z));
StringBuffer txt = new StringBuffer();
StringBuffer txt2 = new StringBuffer();
char ch;
while (rd.ready()) {
ch = (char) rd.read();
txt.append(ch);
}
rd.close();
Pattern p = Pattern.compile("\\.");
Matcher m = p.matcher(txt);
while (m.find()) {
m.appendReplacement(txt2, "!");
}
wr.write(txt2.toString());
wr.close();
}
}