Surcharge de pile - java.lang.OutOfMemoryError
Bonjour,
Voici mon problème, j'ai créer une fonction qui recherche une information (de type String) dans un texte. Cette Recherche se base sur une recherche de la chaine précédente et sur une recherche de la chaine suivante. Une fois ces deux éléments trouvés, on sélectionne le texte contenu entre ces deux positions (via substring) et on met le tout dans une variable Info.content .
La est tout le problème, Le fait de le mettre dans cette variable génère une erreur : java.lang.OutOfMemoryError car je n'ai pas qu'une information a trouvées mais plusieurs. Si j'enlève le "Info.content =" du code tout fonctionne !!! Je pense a une surcharge mémoire mais comment puis je faire pour récupérer cette information qui m'est indispensable ... Si vous pouviez m'éclairer Merci ;)
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
| /**
* This fonction permits to search the Information in the File
*
* @param Info
* @param file
* @return
*/
public boolean SearchInfo(Information Info, File file, String LogPath) {
boolean infoFound = false;
String FileContent;
try {
InputStream in = new BufferedInputStream(new FileInputStream(file));
byte[] bytes = new byte[in.available()];
in.read(bytes);
// Attention pe faut-il utiliser le constructeur (byte[] bytes, //
FileContent = new String(bytes);
// TQ il reste le mot de debut et qu'on a pas trouve if
int beginContent, EndOfContent, newBeforeString;
beginContent = FileContent.indexOf(Info.beforeString);
if (beginContent != -1) {
EndOfContent = FileContent.indexOf(Info.afterString,
beginContent);
if (EndOfContent != -1) {
do {
newBeforeString = FileContent.indexOf(
Info.beforeString, beginContent + 1);
if (newBeforeString != -1
&& newBeforeString < EndOfContent) {
beginContent = newBeforeString;
} else {
Info.content = FileContent.substring(beginContent,
EndOfContent);
infoFound = true;
}
} while (newBeforeString != -1
&& newBeforeString < EndOfContent);
} else {
LogHelper.addText(IHMHelper.logDate()
+ " : Error Information " + Info.label
+ " can not be found ", LogPath);
LogHelper.addText(IHMHelper.logDate()
+ " : Error Reason : " + Info.afterString
+ " can not be found ", LogPath);
}
} else {
LogHelper.addText(IHMHelper.logDate() + " : Information "
+ Info.label + " can not be found ", LogPath);
LogHelper.addText(IHMHelper.logDate() + " : Reason : "
+ Info.beforeString + " can not be found ", LogPath);
}
in.close();
}
catch (IOException e) {
LogHelper.addText(IHMHelper.logDate() + " : ERROR "
+ e.getLocalizedMessage(), LogPath);
}
// System.out.println(Info.content);
return infoFound;
} |