OutputStream op = new FileOutputStream("d:\\test\\student.txt");
        我想在程序里面创建test文件夹! 但是出现如下错误
         java.io.FileNotFoundException: d:\test\student.txt (系统找不到指定的路径。)        我该怎么样创建test这个文件夹呢? (要在程序里面创建哈! 不是鼠标点击创建)

解决方案 »

  1.   

     boolean  exists()
              测试此抽象路径名表示的文件或目录是否存在。
     boolean  createNewFile()
              当且仅当不存在具有此抽象路径名指定的名称的文件时,原子地创建由此抽象路径名指定的一个新的空文件。
    boolean  mkdirs()
              创建此抽象路径名指定的目录,包括创建必需但不存在的父目录。
      

  2.   

            File file = new File("d:\\test\\student.txt");
            if (file.isFile()) {
                try {
                    file.createNewFile();
                } catch (IOException e1) {
                    e1.printStackTrace();              }
            }
      

  3.   

    刚刚的程序逻辑好像有点问题,不好意思
            File file = new File("d:\\test\\student.txt");
            if (!file.isFile()) {
                File dir = new File("d:\\test");
                if (!dir.isDirectory()) {
                    dir.mkdir();
                }
                try {
                    file.createNewFile();
                } catch (IOException e1) {
                    e1.printStackTrace();  
                }
            }