Problème de saut à la ligne en écriture
Bonjour,
je lis un fichier et j'écris dans un autre, le but est de remplacer des chaines de caractères. Tout fonctionne mise à part qu'en recopiant dans mon nouveau fichier il ne veut pas faire de mise à la ligne...
Voici mon code :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
| public class Remplacement {
public static void main(String[] args) throws IOException {
//System.out.println("PASSAGE");
File entree = new File("C:\\toto.txt");
File sortie = new File("C:\\temp.txt");
//System.out.println("PASSAGE");
BufferedReader br = null;
BufferedWriter bw = null;
String ligne="";
try {
br = new BufferedReader(new FileReader(entree));
bw = new BufferedWriter(new FileWriter(sortie));
while ((ligne = br.readLine()) != null) {
System.out.println(traitement(ligne)+"\n");
bw.write(traitement(ligne)+"\n");
}
System.out.println("PASSAGE");
} catch (FileNotFoundException e) {
e.printStackTrace();
} finally {
bw.flush();
br.close();
bw.close();
}
//entree.delete();
sortie.renameTo(new File("C:\\Users\\Yoko\\Desktop\\toto.txt"));
}
public static String traitement(String line) {
int x = 0;
//System.out.println("Taille line : "+line.length());
while (x < line.length()) {
//System.out.println("Valeur X : "+x);
if (x + 6 <= line.length() && line.substring(x, x + 6).equals("maison")) {
//System.out.println("PASSAGE");
String part1 = line.substring(0, x);
String part2 = line.substring(x + 6, line.length());
line = part1+"TOTO"+part2;
}
x++;
}
//System.out.println("new line = "+line);
return line;
}
} |
Voici ce qui s'affiche dans ma console : (le résultat que je souhaite avoir ds mon fichier)
Code:
1 2 3 4
| erkjke,flkz,feTOTOzezdez
dzkedzl TOTO ferkfmlkf
dzedz |
Et ce que j'ai au final dans mon fichier temp.txt ..... :
Code:
erkjke,flkz,feTOTOzezdezdzkedzl TOTO ferkfmlkfdzedzfzeffz
Je suis un peu perdu la...
Merci pour votre aide !