What is the best way to eliminate spaces and points? [closed]

0

This is my code, but the output does not match what I want and you are not separating the space or deleting the dots of all lines in the file.

BufferedReader inf = null;
String line;
String ficheiro;
try {

    inf = new BufferedReader(new FileReader("musicas.txt"));


    while ((line = inf.readLine()) != null) {
        String linha = inf.readLine();
        System.out.println(line);
        String espaco[] = inf.readLine().split(" : ");
        for (String sp: espaco) {
            System.out.println(sp);

        }


    }
} catch (IOException e) {}
    
asked by anonymous 27.06.2017 / 18:29

1 answer

4

You can try as follows:

FileReader fr = new FileReader("musicasentrada.txt"); 
BufferedReader br = new BufferedReader(fr); 
FileWriter fw = new FileWriter("musicassaida.txt"); 
String line;

while((line = br.readLine()) != null)
{ 
    line = line.trim();
    if (!line.equals(""))
    {
        fw.write(line, 0, line.length());
    }
} 
fr.close();
fw.close();
    
27.06.2017 / 18:37