黑马程序员技术交流社区
标题:
FileDialog的文件过滤器用?
[打印本页]
作者:
code_geass
时间:
2013-9-25 01:54
标题:
FileDialog的文件过滤器用?
本帖最后由 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("保存失败");
}
复制代码
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2