"file://" + servletContext.getRealPath("/") + "test.txt"

解决方案 »

  1.   

    如果用相对路径
    ./test.txt和.\\test.txt都行
    要不就用绝对路径
      

  2.   

    如果是根目录的话,可以这样设定path  
    String FilePath=System.getProperty("user.dir");//这是你使用的根目录例如D:\
    如果在d:\的某一个目录的话,
    String FilePath=System.getProperty("user.dir");
    FilePath=FilePath+"具体的目录";//具体的目录用引号引起来。
      

  3.   

    有点错误,改一下!
    如果是根目录的话,可以这样设定path  
    String FilePath=System.getProperty("user.dir");//这是你使用目录
    例如D:\YY
    如果在D:\YY
    的某一个目录的话,
    String FilePath=System.getProperty("user.dir");
    FilePath=FilePath+"具体的目录";//具体的目录用引号引起来。
      

  4.   

    建议你在Classes目录的同一根目录加一个目录放所有的*.txt文档。
      

  5.   

    application.getRealPath("/" +"test.txt");
    已经实验过,在nt,linux 下都能实现,与大家分享。