首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2SE开发 >

java 记事簿 关于 保存功能

2012-09-29 
java记事本 关于 保存功能Java codeString fileNameNoName.txtJava codeelse if(eventSourcesaveIte

java 记事本 关于 保存功能

Java code
String fileName="NoName.txt";


Java code
   else if(eventSource==saveItem){    fileName="NoName.txt";    writeFile(fileName);}   else if(eventSource==saveAsItem){    fileName=null;    writeFile(fileName);


Java code
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);        }    }    




这些是关于 保存功能的。 只能另存可以用, 点保存没任何效果。。各位前辈可以帮看下吗?

[解决办法]
路过,没看懂,代码发的好飘逸~

[解决办法]
如果你想第一次保存弹窗,以后保存不弹窗,可以这样写
Java code
String fileName=null; 

热点排行