What is the best way to eliminate spaces and dots?

Asked

Viewed 83 times

0

This is my code, but the output is not matching with what I want and is not separating the space or deleting the dots from 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) {}
  • Please do not use rollback unnecessarily.

1 answer

4


You can try this way:

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();

Browser other questions tagged

You are not signed in. Login or sign up in order to post.