Hier ist das Problem. Ich habe einigen Text in meiner .txt-Datei, es genau so aussehen wie diese:Entfernen Sie ein bestimmtes Zeichen aus jeder Zeile einer Datei, wenn das auftritt
Bee-bee is the voice that Sheep giv-
e. Mou-Mou is the voice that Cow gi-
ve. Miau-Miau is the voice that Ca-
t gives.
Programm, das ich diese Datei benötigen lesen und verbindet Linie. Ausgang (txt.file):
Bee-bee is the voice that Sheep give. Mou-Mou is the voice that Cow give. Miau-Miau is the voice that Cat gives.
Ich denke, dass ich so etwas wie dies tun müssen:
//Locate the file:
File file = new File("/path/to/file.txt");
//Create a temporary file
File temp = File.createTempFile("file", ".txt", file.getParentFile());
//String I want to remove
String delete = "-";
//open the file, open the tmp file, read the file line by line and replacing signs
for (String line; (line = reader.readLine()) != null;) {
// ...
}
//Delete the string from the line.
line = line.replace(delete, "");
Hier ist ein Problem, dass es "Biene-bee" mit "beebee" in der Ausgabedatei ersetzen und das ist nicht was ich will. Ich brauche etwas Konstruktion "wenn das Zeichen ist" - "und das nächste Zeichen ist Wagenrücklauf, löschen" - "aber ich habe keine Ahnung, wie man das schreibt.
Sie können einen Wagenrücklauf wie folgt in eine Zeichenfolge einfügen: '" \ r "'. Normalerweise endet eine Zeile jedoch mit einer neuen Zeile: '" \ n "'. – markspace