Is is possible to remove the white spaces of a String
in a text file in Java? I have tried my approach but doesn't working.
public static void main(String[] args) throws IOException {
File f = new File("ejer2.txt");
BufferedReader br = new BufferedReader(new FileReader(f));
String linea = br.readLine();
linea.replaceAll("\\s", "");
while (linea != null) {
System.out.println(linea);
linea = br.readLine();
}
br.close();
}
The only way I can get the white spaces out of the String
is when I print the line out in the While
loop by using the replaceAll
method in the String
class, but im trying to take them out of the String
in the File
, and I'm not sure if this is possible.