如果想获取与这个jsp文件同目录下的另一下文件a.txt的File类实例,应该怎样写代码?

解决方案 »

  1.   

    String url = request.getRequestURI();
    url = url.substring(0,url.lastIndexOf("/"));
    File file = new File(url+"a.txt");
      

  2.   

    好像不行,我用file.exists()测试,返回false
      

  3.   

    String path=request.getRealPath("jsp/a.txt");
    File file=new File(path);
      

  4.   

    相对路径试了没?
    File f = new File("a.txt");
      

  5.   

    用request.getRealPath("a.txt")能够访问到正确的文件,但我试了一下访问一个目录,就是request.getRealPath("data"),会出现拒绝访问,能否通过设置使其能访问路径?