練功房推薦書單

  • 猛虎出柙雙劍合璧版--最新 OCA / OCP Java SE 7 Programmer 專業認證 (電子書)
  • 流浪教師存零股存到3000萬(全新增修版)(書+DVD)
  • 開始在關西自助旅行(京都‧大阪‧神戶‧奈良)(全新增訂版)
  • 不敗教主的300張股票存股術

如何將Properties排序輸出? RSS feed
Forum Index » 網頁程式設計 Web Development
Author Message
andowson

七段學員
[Avatar]

Joined: Jan 2, 2007
Messages: 727
Location: 台北
Offline
參考How to sort Properties ??這篇裡面最簡單的作法是:
public class SortedProperties extends Properties {

public synchronized Enumeration keys() {
Enumeration keysEnum = super.keys();
Vector keyList = new Vector();
while(keysEnum.hasMoreElements()){
keyList.add(keysEnum.nextElement());
}
Collections.sort(keyList);
return keyList.elements();
}
}

使用方式就跟原本的Properties類別一樣:

Properties p = new SortedProperties();
p.putAll(globals.installation);
try {
FileOutputStream out = new FileOutputStream(globals.installationConfig);
p.store(out, "Installation specific configuration options");
out.close();
}
catch (IOException e) {
throw new ForumException(e);
}

分享經驗 累積智慧
[WWW]
 
Forum Index » 網頁程式設計 Web Development
Go to:   
Mobile view