Probleme mémoire fonction comparaison fichier
Bonjour,
je dois ecrire un programme permettant de comparer un fichier assez volumineux en sortit 1 rapport d'erreur et une visuel des différences a l'ecran.
mon programme marche tres bien sur des petits fichiers cependant des que le fichiers devients assez volumineux celui ci rame enormement.
je pensse que cela est du a la taille mémoire trop important de ma variable rapport et visuel.
mon but étant dafficher ce rapport a l'ecran donc par l'intermédiaire d'une fenetre d'un texarea.C'est pour cela que je stock mes informations dans un type STRING.
auriez vous une autre idée de methode ?
programme ci joint
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 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135
| public class comparaison extends Thread
{
String rapport;
String exep_file;
String regle_file;
fenetrePrincipale mainFen;
FileInputStream fichier1;
FileInputStream fichier2;
public void setExeptFile(String file)
{
exep_file=file;
}
public void setRegleFile(String file)
{
regle_file=file;
}
public void run ()
{
chargement dwl = new chargement(regle_file);
chargement exep = new chargement(exep_file);
int cpt2=0;
int pos=1;
int line=0;
int cpt=0;
int cptexep=0;
String ligne_rapport;
boolean erreur=false;
boolean regle=false;
boolean exeption=false;
boolean err=false;
rapport="RAPPORT COMPARAISON : \n";
String visuel;
visuel = "Visualisation des ecarts : \n\n";
try
{
InputStreamReader streamReader1=new InputStreamReader(fichier1);
BufferedReader buffer1=new BufferedReader(streamReader1);
String line1="";
InputStreamReader streamReader2=new InputStreamReader(fichier2);
BufferedReader buffer2=new BufferedReader(streamReader2);
String line2="";
mainFen.textArea_resultat_comparaison.setText("Chargement ...");
while ( null!=(line1=buffer1.readLine()) && null!=(line2=buffer2.readLine()))
{
line++;
visuel=visuel+"\n";
pos=1;
cpt=0;
System.out.print(line+"\n");
if (rapport.length()>40000)
{
rapport = "Nombre d'erreurs anormales, le programme ne peut continuer.\n\n"+rapport;
break;
}
while( cpt < line1.length() )
{
if(line1.charAt(cpt) != line2.charAt(cpt))
{
while(cptexep!=exep.len)
{
if(exep.pos_d[cptexep]<=pos && exep.pos_f[cptexep]>=pos )
{
exeption=true;
}
cptexep++;
}
if(exeption==false)
{
visuel=visuel+line1.charAt(cpt);
erreur=true;
err=true;
while(cpt2!=dwl.len)
{
if(dwl.pos_d[cpt2]<=pos && dwl.pos_f[cpt2]>=pos )
{
ligne_rapport = "\n Erreur enregistré : "+dwl.libelle[cpt2]+" line : "+line+" pos : "+pos;
rapport += ligne_rapport;
regle=true;
}
cpt2++;
}
if(regle==false)
{
ligne_rapport = "\n Erreur non enregistré line : "+line+" pos : "+pos;
rapport += ligne_rapport;
}
}
if(err==false)
{
visuel=visuel+".";
}
}else{visuel=visuel+".";}
cpt++;
cpt2=0;
pos++;
exeption=false;
regle=false;
err=false;
cptexep=0;
}
}
if (erreur==false)
{
ligne_rapport = "\nLes fichiers sont identiques ";
rapport += ligne_rapport;
}
mainFen.textArea_resultat_comparaison.setText(rapport);
fichier1.close();
fichier2.close();
System.out.print(visuel);
}
catch (FileNotFoundException e)
{
}
catch (IOException e)
{
}
}
} |