我正在嘗試爲我爲Minecraft製作的MOD生成一個屬性文件。如何阻止屬性類以不合邏輯的順序輸出到文件。解決方法?
mod將依賴很多這個屬性文件。它應該看起來像這樣:
#Comment
#More Comment
#Even more comment explaining.
Button1=Button1 #The data after the equals they would change
Button1Command=/help
Button2=Button2
Button2Command=/rules
這將重複超過30按鈕。下面是我用來生成在配置這些選項19的測試代碼:
Properties p = new Properties();
try {
File configDir = new File(Minecraft.getMinecraftDir(), "/config/");
File config = new File(configDir, "FogHelperConfig.cfg");
// set the properties value
for(int c = 18;c >= 0;c--)
{
p.setProperty("Button"+c, "Button"+c);
}
// save properties minecraft config folder.
p.store(new FileOutputStream(config), null);
} catch (IOException ex) {
ex.printStackTrace();
}
}
此
Button18=Button18
Button17=Button17
Button9=Button9
Button16=Button16
Button8=Button8
Button15=Button15
Button7=Button7
Button14=Button14
Button6=Button6
Button13=Button13
Button5=Button5
Button12=Button12
Button4=Button4
Button11=Button11
Button3=Button3
Button10=Button10
Button2=Button2
Button1=Button1
Button0=Button0
輸出當然,這是當我處理一些需求的主要問題按照邏輯順序排列,因爲它有編號。如果沒有數字,我可以看到這是好的,但在這種情況下它必須按順序排列。
我假設我可以做些什麼或某種解決方法來解決Java Properties類所具有的問題。我願意擁有一個屬性文件,我將手工製作和打包mod,並將它放置在特定的位置,但我更願意讓它生成,因爲它更友好。
另外我需要做的事情是給這個道具文件添加註釋,雖然我不太確定如何去做。
歡迎任何不同的方式來做到這一點!無論什麼作品!
在此先感謝!
屬性本身是無序的。 [Commons Configuration](http://commons.apache.org/configuration/howto_properties.html#Layout_Objects)對處理註釋和結構有一定的支持。不過,通過排序後處理文件可能會更容易。 – 2012-02-21 21:06:43
@DaveNewton只要我用任何方式完成我的任務,我不介意做不同的方式。後期處理會很好,只是我對Java的瞭解並不是最好的,所以我可能會遇到一些麻煩。 – ComputerLocus 2012-02-21 21:27:09