fileinputstream - Java FIleinputout and fileoutput -


try {        system.out.println(f.getabsolutefile());       //   fileinputstream input = new fileinputstream(f);         fileinputstream inp = new fileinputstream("c:\\users\\jamal\\desktop\\japaneseword1.xls");        workbook workbook = new hssfworkbook(inp);        fileoutputstream output = new fileoutputstream("c:\\users\\jamal\\desktop\\japaneseword2.xls");         sheet sheet2 = workbook.getsheet("japaneseword");                     int num = sheet2.getlastrownum();        num=++;        system.out.print(num);        row row = sheet2.createrow(num);        cell cell = row.createcell(0);        cell.setcellvalue(japaneseword);        cell cell2 = row.createcell(1);        cell2.setcellvalue(japaneseword);        cell cell3 = row.createcell(2);        cell3.setcellvalue(japaneseword);        cell cell4 = row.createcell(3);        cell4.setcellvalue(japaneseword);        cell cell5 = row.createcell(4);        cell5.setcellvalue(japaneseword);        cell cellwebsite = row.createcell(5);         workbook.write(output);     }     catch(exception e){         e.printstacktrace();     }         } 

the purpose of code save contents,add row, , add user's input excel file. used inputstream attempt save previous entries,then add new entries, , use outputstream print out excel file. have done in past no problems, reason inputstream not saving correctly. frustrated @ problem. love know why happening.

thanks.

--- update ---

okay, update, reason or another, works occasionally. see if create file, using above method won't copy correctly. if change file name in constructor of outputstream method different name on excel document arbitrary starts counting rows. saves data correctly , works intended. make sense?

basically, after create file, have go back, change code, saves , copys data, , can continue edit file. solution not practical.

you must close streams, outputstreams. otherwise can loose data.

at end must do

 output.close();  inp.close(); 

Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -