java - Checking if file exists, if so, dont create new file and append instead -
private void saveformactionperformed(java.awt.event.actionevent evt) { name = nameformtext.gettext(); surname = surnameformtext.gettext(); age = integer.parseint(ageformtext.gettext()); stadium = stadiumformtext.gettext(); venues fix = new venues(); fix.setname(name); fix.setsurname(surname); fix.setage(age); fix.setstadium(stadium); file outfile; fileoutputstream fstream; objectoutputstream ostream; try { outfile = new file("output.data"); fstream = new fileoutputstream(outfile); ostream = new objectoutputstream(fstream); ostream.writeobject(fix); joptionpane.showmessagedialog(null, "file written successfully"); ostream.close(); } catch (ioexception e) { system.out.println(e); } }
this have far. ideas on append file if it's created?
you have first check if file exists before, if not create new one. learn how append object objectstream take @ question.
file outfile = new file("output.data"); fileoutputstream fstream; objectoutputstream ostream; try { if(!outfile.exists()) outfile.createnewfile(); fstream = new fileoutputstream(outfile); ostream = new objectoutputstream(fstream); ostream.writeobject(fix); joptionpane.showmessagedialog(null, "file written successfully"); ostream.close(); } catch (ioexception e) { system.out.println(e); }
Comments
Post a Comment