2013-07-04 54 views
1

我建一個性質/ RAW文件,當我看到文件,它是沒有問題的:如何在android的原始文件中編寫屬性文件?

public static String readProperties(String filePath, String parameterKey) { 
    String result = null; 
    Properties pro = new Properties(); 
    try { 
     pro.load(GlobalVariate.class.getResourceAsStream(filePath)); 
     // pro.load(GlobalVariate.class 
     // .getResourceAsStream("/assets/config.properties")); 
     result = pro.get(parameterKey).toString(); 

    } catch (IOException e) { 
     System.out.println("load fail:" + e); 
     e.printStackTrace(); 
    } 
    return result; 
} 

,但是當我把它寫說,文件路徑是不存在的:

public void saveConfig(Context context, String file, Properties properties) { 
    try { 
     FileOutputStream s = new FileOutputStream(file, false); 
     properties.store(s, ""); 
     System.out.println("write success!"); 
    } catch (Exception e) { 
     e.printStackTrace(); 
     System.out.println("write error:+" + e); 
    } 
} 

saveConfig(this, "/assets/config.properties", prop); 

回答

1

你剛纔提到,你想讀取寫入屬性文件到/ raw文件夾中,但是在這裏你似乎正在將文件寫入到assests文件夾中。所以更改

/assests.config.properties 

/raw/config.properties 
相關問題