使用绝对路径
"/xxx"
/指你的项目的根目录,就是<Contex DocBase="xxx"...里面的路径

解决方案 »

  1.   

    package myone ;import java.io.*;
    import java.util.*;public class news
    {
      private String path;
      private StringBuffer newstext = new StringBuffer();
      public void setpath(String path)
      {
        this.path = path;
      }  public String getpath()
      {
        return path;
      }  public String gettext()
      {
        try
        {
          FileInputStream news = new FileInputStream(path);
          byte buff1[] = new byte[99999];
          int  i= news.read(buff1);
          if (i != -1)
          {
            newstext=new StringBuffer(new String(buff1));//注意这里 newstext=new StringBuffer("\"+new String(buff1));
          }
          news.close();
          String text = new String(newstext);
          return text;
        }
        catch (Exception e)
        {
          System.out.println(e);
        }
        return null;
      }
    }
      

  2.   

    可以,默认的当前目录是;myone                       +- classes  
                             +- myone
                               +- news
                             +- resources
                               +- mytest.properties  
                             +- my.txtFile file = new File("my.txt");
    File file2 = new File("./resources/mytest.properties");
      

  3.   

    File file=new File("");
    System.out.print(file.getAbsolutePath());
      

  4.   

    jsp里面的javabean默认路径不是当前目录,我以前遇到过同样的问题的
      

  5.   

    用相对路径的话就更难处理了.相对于类所在位置的路径.最简单就是和类文件放在一起.我也是比较同意 xlhacoo(自古华山一条路) 的说法,用相对路径确定一个绝对路径,这样可以万无一失,在使用过种中可见的是相对路径,但访问的时候其实是通过绝对路径访问的..
    这样无论是在window还是在linux上都OK.