Fichiers en java

Fermé
Aaa_dh Messages postés 10 Date d'inscription mardi 26 janvier 2016 Statut Membre Dernière intervention 11 avril 2016 - 11 avril 2016 à 14:58
Bonsoir;
Je suis débutante en java et je dispose de deux fichiers en input, le premier contient des indexes er le deuxieme contient un ensemble de phrases. Voici un exemple du premier fichier:

0 1 3
2 1
4 2
....
3 1

et le deuxieme fichier:

my name is
the task is hard
this site is helpful
the java code is fluent
IT's sunny
I have a problem

je voudrais utiliser ces deux fichiers pour avoir un troisieme fichier qui contient les phrases du deuxieme fichier selon les indexes du premier fichier de la forme suivante:

my name is
the task is hard
the java code is fluent
####
this site is helpful
the task is hard
####
IT's sunny
the task is hard
####
.....
####
the java code is fluent
the task is hard

J'ai essayé avec ce bout de code mais j'ai pas eu le résultat souhaité:

public void CreateFileForCliques(String file1Path,String file2Path,String outputFile)
{
String file1Content = readFile(file1Path, StandardCharsets.UTF_8);
String file2Content = readFile(file1Path, StandardCharsets.UTF_8);
String[] file1sentences = file1Content.split("[\n]");
String[] file2sentences = file2Content.split("[\n]");
StringBuilder builder = new StringBuilder();

for (int i = 0; i < file1sentences.length; i++){

for (int j = 0; j < file2sentences.length; j++){
String[] sentenceWords = file2sentences[j].split("\\s+");
int[] tab=new int[sentenceWords.length];
for (int k = 0; k < sentenceWords.length; k++){
String selectedWord = sentenceWords[k];
int conv=Integer.parseInt(selectedWord);



builder.append(file1sentences[conv] + "\n");
}
writeIntoFile(builder, outputFile,true);
}
}
}



public static void writeIntoFile(StringBuilder stringBuilder,
String txtFilePath, boolean append) {
File file = new File(txtFilePath);

// if file doesn't exists, then create it
if (!file.exists()) {
try {
file.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
}
FileWriter fw;
try {
fw = new FileWriter(file.getAbsoluteFile(), append);
BufferedWriter bw = new BufferedWriter(fw);
bw.write(stringBuilder.toString());
bw.close();
} catch (IOException e) {
e.printStackTrace();
}

}


J'ai toujours comme sorti la première ligne du fichier indexes!!!!
Est ce que quelqu'un peut me dire ou modifier le code pour avoir le résultat?
Merci d'avance