File projectDir = new File("d:\\MyProject\\imageView\\");
projectDir.mkdir() ;
创建完成以后,如何直接打开,弹出一个文件夹窗口?

解决方案 »

  1.   


    public static void main(String[] args) {
         String path = "d:\\MyProject\\imageView\\";
         File projectDir = new File(path);
         projectDir.mkdir() ; 
         JFrame frame = new JFrame();
         JFileChooser jfChooser = new JFileChooser(path);
         jfChooser.setDialogTitle("选择文件");
    jfChooser.setFileFilter(new FileFilter() {
    @Override
    public boolean accept(File f){
    if(f.getName().endsWith("txt") || f.isDirectory()) 
    return true;
    return false;
    }
    @Override
    public String getDescription(){
    // TODO Auto-generated method stub
    return "文本数据(*.txt)";
    }
    });
    frame.add(jfChooser);
    frame.setBounds(100,200,400,300);
    frame.setVisible(true);
        }
      

  2.   


    import java.io.File;
    import java.io.IOException;public class Test { public static void main(String[] args) throws IOException {
    File projectDir = new File("d:\\MyProject\\imageView\\");
    projectDir.mkdirs();
    Runtime.getRuntime().exec("explorer " + projectDir.toString());
    }
    }注意:我把mkdir改成了mkdirs
      

  3.   


    就是这种效果,太好了!在linux平台下或者其他平台下怎么实现呢?
      

  4.   

    这个是调用操作系统的程序来运行。在Linux里就需要调用Linux的窗口程序,GNOME、KDE可能还有些不一样。另外Linux经常是命令行,那就根本没有办法。