日期:2014-05-20 浏览次数:20786 次
String fileName="NoName.txt";
else if(eventSource==saveItem){ fileName="NoName.txt"; writeFile(fileName); } else if(eventSource==saveAsItem){ fileName=null; writeFile(fileName);
public void writeFile(String name){ File filea ; String messagef="文件未找到"; FileOutputStream outputfile=null; if(fileName==null){ JFileChooser savefile=new JFileChooser(); savefile.setDialogTitle("保存文件"); savefile.setApproveButtonText("保存"); savefile.showSaveDialog(this); filea=savefile.getSelectedFile(); if(filea==null)return; } else { filea=new File(fileName); } try{ outputfile=new FileOutputStream(filea); } catch(FileNotFoundException e){ JOptionPane.showMessageDialog(this, messagef, title, type); } String filecontent=textArea.getText(); String messaget="下文件错误"; try{ outputfile.write(filecontent.getBytes()); } catch(IOException e){ JOptionPane.showMessageDialog(this, messaget, title, type); } String messagee="关闭流发生错误"; try{ outputfile.close(); } catch(IOException e){ JOptionPane.showMessageDialog(this, messagee, title, type); } }
String fileName=null;