本帖最后由 code_geass 于 2013-9-25 02:00 编辑
- public void othersave()
- {
- //建立文件名过滤器
- FileDialog fdsave=new FileDialog(f,"打开",FileDialog.LOAD);
- File file=null;
- FilenameFilter ff=new FilenameFilter()
- {
- public boolean accept(File dir,String name)
- {
- return dir.getName().endsWith("java")||dir.getName().endsWith("txt");
- }
- };
-
- fdsave.setFilenameFilter(ff);
-
- fdsave.setVisible(true);
- String s2=fdsave.getFile();
- String s3 =fdsave.getDirectory();
- if(s2==null||s3==null)
- return;
- file =new File(s3,s2);
- try
- {
- if(!(file.exists()))
- file.createNewFile();
- }
- catch (IOException ex)
- {
- throw new RuntimeException("建立失败");
- }
-
- BufferedWriter bw =null;
- try
- {
- bw=new BufferedWriter(new FileWriter(file));
-
- bw.write(ta.getText());
- bw.close();
- }
- catch (IOException ex1)
- {
- throw new RuntimeException("保存失败");
- }
-
复制代码 |