PDA

View Full Version : [java]Stack OverFlow Error


wizard1993
07-12-2008, 21:24
Sto scrivendo un programma che di fatto è concettualmente semplice (si tratta di togliere una parte di stringa da file di input e riscriverlo in output)
il problema è che il programma parsa file da 10^5 righe, e incorro in uno StackOverflowError, posto il codice della classe, cosa mi consigliate?

public class spitfile {
Scanner input;
PrintStream ps;
StringBuilder[] sb;
public spitfile(String filename){
try{
input=new Scanner(new File(filename));
ps=new PrintStream("output.txt");
}
catch(Exception ex){
ex.printStackTrace();
}
}
public void run(String sep){
buffer(sep);
}
public void split(String sep){
for (int i = 0; i < sb.length; i++) {
StringBuilder stringBuilder = sb[i];
if (stringBuilder==null)return ;
int k=stringBuilder.indexOf(sep);
if(k!=-1)
sb[i]=stringBuilder.replace(k,sb.length,"");
}
write();
buffer(sep);
}
public void buffer(String sep){
sb=new StringBuilder[128];
for(int i=0;i<sb.length &&input.hasNext();i++){
sb[i]=new StringBuilder(input.next());
}
split(sep);
}
public void write(){
for (StringBuilder stringBuilder : sb) {
ps.println(stringBuilder.toString());
}
ps.flush();
}
}


Vi ringrazio anticipatamente, il metodo d'entrate è il metodo run

Oceans11
08-12-2008, 09:37
Ti consiglio di cambiare codice :D
Prova a renderlo iterativo, problemi non dovresti averne.

Hardware Upgrade Forum Database Error
Database Error Database error
The Hardware Upgrade Forum database has encountered a problem.

Please try the following:
  • Load the page again by clicking the Refresh button in your web browser.
  • Open the www.hwupgrade.it home page, then try to open another page.
  • Click the Back button to try another link.
The www.hwupgrade.it forum technical staff have been notified of the error, though you may contact them if the problem persists.
 
We apologise for any inconvenience.