贴一部分使用绝对路径的代码:
Properties myPro = new Properties();
try
{
FileInputStream fis = new FileInputStream("c://MyPro.properties");
myPro.load(fis);
//访问操作
}
catch (IOException e)
{
//Exception处理
}

解决方案 »

  1.   

    我以前的代码:
    try {
          String configFile = System.getProperties().getProperty("user.dir") + System.getProperties().getProperty("file.separator") + "conf" + System.getProperties().getProperty("file.separator") + "default.ini";
          FileInputStream config_in = new FileInputStream(configFile);
          defaultPreference.load(config_in);
          config_in.close();
        } catch (Exception ex) {
          ex.printStackTrace();
        }读取用户(其实是应用程序)的宿主目录\conf\default.ini文件到一个Properties相对路径是相对的什么我不说了,你可以自己println出来看看就明白了:)
      

  2.   

    简单方法:读取Prop.propertiesstatic ResourceBundle resources = ResourceBundle.getBundle("Prop");
    String value = resources.getString("Key");这种方法下,你的Prop.properties只要放在classpath所指的某个路径或Jar文件中就可以了。
      

  3.   

    Apocalypse(逍遥思辨):
    我现在还只是在jbuilder下调试,没有部署环境,所以再请问一个问题
    如果我的应用程序是部署在tomcat上,那么读取用户(其实是应用程序)的宿主目录是那个目录,也就是System.getProperties().getProperty("user.dir")返回什么呢?
      

  4.   

    同意 leonzhao(灯泡) 
    没有比这更简单的了吧?
      

  5.   

    假设你的project在C:\jbproject\untitled1,编译输出在C:\jbproject\untitled1\classes,那么用jbuilder运行程序时user.dir就是C:\jbproject\untitled1。
      

  6.   

    I suggest you using java.util.prefs.Preferences
    http://www-106.ibm.com/developerworks/java/library/j-mer1002/
    Working with preferences
      

  7.   

    首先:import java.util.PropertyResourceBundle;
    然后:
    private StringpvCONFIG_BUNDLE_NAME
    =CMN_JPT_PropConstant.pbstCONFIG_BUNDLE_NAME;PropertyResourceBundle aPropertyResourceBundle=
           (PropertyResourceBundle)PropertyResourceBundle.getBundle(
                pvCONFIG_BUNDLE_NAME);
            String strJSP_PATH=aPropertyResourceBundle.getString(
                "JSP_PATH")+"jsp/crp/JPTCRP_Sheet1.jsp";
            String strQuery_PATH=aPropertyResourceBundle.getString(
                "QUERY_PATH")+".crp.JPTCRP_SheetQuery1";
    其中主要的是上面的方法
    而下面的strJSP_PATH,QUERY_PATH是我在属性文件内写的定义query和jsp以及form的位置,参考就可以了