labiche54 | Bonjour, Essayant de développer une appli pour la synchronisation des sous titres, je suis em...dé par la fonction PrintWriter qui, je ne sais pas pourquoi, s'arrête brusquement de fonctionner sans afficher un qqc message d'erreur. Plus précisément, mon appli fonctionne comme ça : dans une boucle While, je lis dans mon fichier de sous titre une ligne, si elle doit être modifiée je la modifie, puis je la réécris dans un fichier ".txt" que j'ai créé avant de rentrer dans ma boucle. Ma condition d'arrêt est qu'il n'y ai plus de ligne à lire. Ayant inséré un compteur, je vois bien que ma boucle tourne jusqu'à la condition d'arrêt demandée, mais ce PrintWriter de m..... s'arrête à environ 2% du fichier de départ, je ne vois pas du tout pourquoi ! Voici le code : (c'est un peu du travail de bourin (je débute ))
Code :
- import java.io.*;
- public class Synchroniseur {
- public static void affiche(String avance_sec, String deformation, String cheminFichier, String nomFichier) throws IOException
- {
- String ligne;
- cheminFichier = cheminFichier.replace('\\','/');
-
- try
- {
- double sec_sync = Double.parseDouble(avance_sec);
- double a=-Double.parseDouble(deformation);
- BufferedReader ficTexte;
- ficTexte = new BufferedReader(new FileReader(new File(cheminFichier+'/'+nomFichier)));
-
- File sortie = new File(cheminFichier+"/temp.srt" );
- PrintWriter out = new PrintWriter(new FileWriter(sortie));
- if (ficTexte == null)
- {
- throw new FileNotFoundException("Fichier non trouvé: "+ nomFichier);
- }
- int k = 0;
- String ancLigne_i="00000000000000000000000000000";
- Plage anciNplage;
- Plage nouvLplage = new Plage(ancLigne_i);
- double nouvoSup_i = 0;
- double nouvoInf_i = 0;
- double ancienSup_i;
- while ((ligne = ficTexte.readLine()) != null){
- if (ligne != null)
- {
- boolean present = testCharTable.chainePresente(ligne,"-->" );
- if (present)
- {
- if (k==0) {ancienSup_i = sec_sync;}
- else
- {
- ancienSup_i = nouvLplage.plageSup;
- }
- anciNplage = new Plage(ancLigne_i);
- double ancienSup = anciNplage.plageSup;
- ancLigne_i = ligne;
- nouvLplage = new Plage(ligne);
- double nouvoInf = nouvLplage.plageInf;
- double nouvoSup = nouvLplage.plageSup;
- nouvoInf_i = ancienSup_i + (1-a)*(nouvoInf-ancienSup);
- nouvoSup_i = nouvoInf_i + (1-a)*(nouvoSup-nouvoInf);
- nouvLplage.plageInf = nouvoInf_i;
- nouvLplage.plageSup = nouvoSup_i;
- nouvLplage.Converti();
- Merge(nouvLplage,ligne);
- Printer(nouvLplage, ligne, out);
- k++;
- }
- else
- {
- String str_i = new String(ligne.toCharArray());
- InterfaceAuto.listeMod.addElement(str_i);
- InterfaceAuto.listeModS.addElement(str_i);
- try{
- out.println(ligne);
- }
- catch(Exception e){
- e.printStackTrace();
- }
- }
- }//fin if
- }//fin while
- }
- catch (FileNotFoundException e) {
- System.out.println(e.getMessage());
- }
- catch (IOException e) {
- System.out.println(e.getMessage());
- }
- }
- public static void Merge(Plage plage, String ligne) {
- String str = "abcdefghijklmnopqrstuvwxyzéèà";
- String str_i = ligne;
- for(int i=0; i<29;i++)
- {
- if(i==2||i==5||i==8||i==12||i==13||i==14||i==15||i==16||i==19||i==22||i==25)
- {
- char tmp = str.charAt(i);
- str = str.replace(tmp,ligne.charAt(i));
- }
- else
- {
- char c=' ';
- if (plage.chiffre[i] >= 0 && plage.chiffre[i] <= 9)
- {
- c = Character.forDigit(plage.chiffre[i], 10);
- }
- char tmp = str.charAt(i);
- str = str.replace(tmp,c);
- }
- }
- InterfaceAuto.listeMod.addElement(str_i);
- InterfaceAuto.listeModS.addElement(str);
- }
- public static void Printer(Plage plage, String ligne, PrintWriter out) {
- try{
- for(int i1=0; i1<29;i1++)
- {
- if(i1==2||i1==5||i1==8||i1==12||i1==13||i1==14||i1==15||i1==16||i1==19||i1==22||i1==25)
- {
- out.print(ligne.charAt(i1));
- }
- else out.print(plage.chiffre[i1]);
- }
- out.println();
- }
- catch(Exception e){
- e.printStackTrace();
- }
- }
- }
|
|