我在web项目src目录下有一个assign.properties文件,现在我想要在其他目录下获取这个文件
用FileInputStream inputstream = new FileInputStream(filepath);
请问filepath的路劲应该是什么呢?

解决方案 »

  1.   

    可以用jsp控件file点了选路径,然后触发java写入流  response.getWriter() ..
      

  2.   


    1.FileInputStream in = null;   
    2.Properties properties = new Properties();   
    3.String classpath = null;   
    4.try{       
    5.    classpath = Thread.currentThread().getContextClassLoader().getResource("/").toString();   
    6.    classpath = classpath.substring(5);   
    7.    in = new FileInputStream(classpath+"filename");   
    8.    properties.load(in);   
    9.}catch (Exception e) {   
    10.    System.err.println(classpath+"filename not found");   
    11.        return false;   
    12.}  http://yakar.javaeye.com/blog/221512
      

  3.   

    String path = ServletActionContext.getServletContext().getRealPath("你的文件");
      

  4.   

    先写入流,在读取!fileload()是关键!
      

  5.   

    src 里的java文件发布的时候是装编译过后的class文件放到web-inf/classes下的,所以属性文件也是放到这下面
      

  6.   

    很多人建议用getRealPath但是我更建议LZ读CLASSPATH 这样更正常些
      

  7.   


    确实很少人用读取CLASSPATH这样的方法,这是我第一次见到,学习了.
      

  8.   

    读文件的话,用文件流读是可以的,建议加上 spring框架,把 .proerties配置到 application*-context.xml中,就可以用 java.util.Properties 直接读啦。