Formatar um arquivo txt

Tudo oque quero fazer é ler um arquivo txt e escrever em outro quebrando de linha onde existe um ponto final. No arquivo que estou lendo pode haver qualquer coisa desde uma quantidade grande de linhas em branco e vários pontos finais na mesma linha.

Gostaria de saber porque o código abaixo não funciona em algumas situações?

public static void formatSentences(File entrada, File saida){

        // cria o Scanner para ler e o PrintWriter para escrever

        Scanner sc = null;
        PrintWriter pw = null;
        String linha="";

        try {
            sc = new Scanner(entrada);
            pw = new PrintWriter(saida);
            // enquanto houverem mais linhas na entrada
            while (sc.hasNextLine()) {
                String aux = sc.nextLine();
       
                linha = linha+aux;
                
                // quebra a linha somente se existir um ponto, se não vai concatenando

                if (linha.contains(".")){
                    linha = linha.replace(". ", ".\n");
                    pw.print(linha.trim());
                    linha = "";
                }else
                    linha = linha+" ";
                }
            // informa que tudo correu bem
            System.out.println("Arquivo processado com sucesso!");
        } catch (FileNotFoundException e) {
            // como verificamos se os arquivos existiam antes, isso não deve ocorrer
            // mesmo assim é boa prática capturar e tratar essa exceção
            System.err.println("Não foi possível econtrar arquivo: " + e.getMessage());
        } finally {
            // para finalizar, fechamos os recursos que usamos
            if (sc != null) {
                sc.close();
            }
            if (pw != null) {
                pw.flush();
                pw.close();
            }
        }
    }

Desde já grato pela colaboração!

em quais situações da erro ?

Fui fazer um teste aqui fiz o seguinte codigo

try {
            FileInputStream input = new FileInputStream(new File("C:\\Users\\cristian.urbainski\\Desktop\\dell.txt"));
            
            byte[] arq = new byte[input.available()];
            
            input.read(arq);
            
            System.out.println(new String(arq).replaceAll(".", "!"));
            
            input.close();
        } catch (Exception e) {
            e.printStackTrace();;
        }

e o resultado foi que ele trocou todos os caracteres do arquivo pelo ponto de exclamacao, que loco, sabem porque acontece isso

Agora funcionou, quebrou a linha no ponto final, veja como ficou o codigo

        try {
            FileInputStream input = new FileInputStream(new File("C:\\Users\\cristian.urbainski\\Desktop\\dell.txt"));
            
            byte[] arq = new byte[input.available()];
            
            input.read(arq);
            
            System.out.println(new String(arq).replaceAll("\\.", "\\.\n"));
            
            input.close();
        } catch (Exception e) {
            e.printStackTrace();;
        }

no site diz que tenho 3 respostas mas não consigo ver. oque será que está acontecendo?

em algumas situação simplesmente não funciona cristian.

tente com o texto abaixo codificação UTF-8



The watchmaker's gold wallet is embroidered and stamped with a picture of 
the village green. Dense black hair sits on his head in uncombed clumps and 
there are small tufts from his nose that melt into his moustache. I see him 
standing outside of his shop, under the awning, his thick arms tapering down 
into delicate hands that have been shaped by small motions. At times I think 
he has no face. There is bone and flesh. There are networks of nerves, veins 
and arteries that lace through the surfaces. But sometimes he seems to have 
transformed himself into a blank, a man who sits in the corner and talks to 
the grandfather clock.

In his coat pocket there is a red satin cushion. This man plays the violin, 
has small hard calluses on the tips of the fingers of the left hand, is an 
unbeliever. It would be easy for him to do certain things. He could set all 
the clocks in his shop to different times. He could grow a beard. He could 
eat fish sandwiches for lunch or bet on horses. But he restrains himself. He 
fears that he will reduce his options, lose the mornings under the awning, 
earn the enmity of his grandfather clock.

His wife would like a new coat. His daughter would like to travel in Europe. 
He lives in the midst of expectations. So I see him in the summer, under the 
awning, standing in the shade not even pretending to look for customers. He 
is pretending he is a shopkeeper. Or he is just letting himself stand 
blankly for a moment. Perhaps he is unaware of what he looks like. But his 
wife and daughter must surely catch it sometimes, notice that he has 
disappeared.
In the winter I sit with him in the corner by the grandfather clock. I try 
to extract his wisdom, hoping he will dispense it lo little lumps.

Att.

na verdade preciso tanto quebrar onde tem pontos e unir (concatenar) as linhas que não tem ponto final.