File newdir = new File("filePath");//filePath写成绝对路径试过没?

解决方案 »

  1.   

    File newdir = new File("/filePaht");
      

  2.   

    因为Tomcat运行的时候根目录指向TOMCAT/BIN,也就是说你不指定路径创建文件的话,它就会放在tomcat/bin 下面。所以你的文件的相对路径应该根据tomcat/bin来,例如:..\webapps\yourweb
    在web程序里面不应该出现绝对路径的!
      

  3.   

    to  whirlwind526 (旋风)  我用你的代码运行后,文件夹被建在了 system32\ 下面!!!但是改成 /mylove 后,被建到了系统盘的 根目录下!!!改成 File newdir = new File( getServletContext().getRealPath("/") + "mylov4" );
    后建到了应用的下面。
    //------------------
    File newdir = new File("mylove");//其中filePath是你要建的路径,        if(newdir.exists()==false)//如果文件夹不在则新建
        { 
        flag = newdir.mkdir();
       }
            if(flag==true)
        {
          out.print("<script>alert('success');</script>"+newdir);
        }
    else
    {
      out.print("<script>alert(\"文件创建失败! \");</script>");
    }