Adding onto a file with java AWT FileDialog and FileWriter -


i having problem code. using awt filedialog, , creating files work fine. in program, have option add text existing file, not add text file. cannot figure out solution, because not returning errors. here code:

if (optiondialog == 1) {                     filedialog fc = new filedialog(form, "choose file open", filedialog.load);                     fc.setdirectory("~/");                     fc.setvisible(true);                     string filename = fc.getfile();                     if (!filename.isempty()) {                         stuff = new file(fc.getdirectory() + fc.getfile());                         form.studentnamebox.requestfocus();                         form.setvisible(true);                         system.out.println(stuff);                         novalidinput = false;                     }                     else {                         joptionpane.showmessagedialog(null, "error! no name entered, please go , try again.");                     }                 } 

this method writes file:

public static void addtofile() throws ioexception {         filewriter fw = new filewriter(main.stuff, true);         (int = 0; < grades.size(); i++) {             fw.write(grades.get(i) + system.getproperty("line.separator"));         }         fw.close();     } 

this code worked jfilechooser, windows came ugly on macs. said, can write file if didn't exist beforehand, cannot edit or add on existing files, wasn't issue jfilechooser. also, method gets called when window closing (done windowlistener) or when quit button pushed on jframe created.


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -