2013-02-22 41 views
1

有誰知道在Java中的屬性文件中是否可以有小寫字母? 目前,當我有實例:Java中較低的屬性

My_Conf=1234567 

我得到的,檢查代碼中的財產

My_Conf=null 

時。

該代碼假設在Jboss servlet引擎中運行。

問候

+2

請嘗試重現這在很短,但*完整*控制檯應用程序。我懷疑你實際上並沒有加載你認爲你正在加載的屬性文件。 – 2013-02-22 13:58:51

+0

我可以認爲該文件加載正確,因爲如果我將其編輯爲大寫,它可以工作,我可以看到更改。 此外,我在代碼本身中添加屬性,結果相同。 – Hiny 2013-02-22 14:00:17

+0

然後,您的代碼依賴於使用'.toUpperCase'檢索屬性的自定義邏輯。 – 2013-02-22 14:03:58

回答

0

試試這個用於調試目的:

String filename = "example.properties"; 
    Properties properties = new Properties(); 
    BufferedInputStream stream = null; 
    try { 
     stream = new BufferedInputStream(new FileInputStream(filename)); 
     try { 
      properties.load(stream); 
      String prop = properties.getProperty("My_Conf"); 
      System.out.println(prop); 
     } catch (IOException e) { 
      System.out.println("IOException"); 
     }finally{ 
      try { 
       stream.close(); 
      } catch (IOException e) { 
       e.printStackTrace(); 
      } 
     } 
    } catch (FileNotFoundException e) { 
     System.out.println("File not found"); 
    }