JWorld@TW the best professional Java site in Taiwan
      註冊 | 登入 | 全文檢索 | 排行榜  

» JWorld@TW » Java 技巧文件  

按列印兼容模式列印這個話題 列印話題    把這個話題寄給朋友 寄給朋友    訂閱主題
reply to topicthreaded modego to previous topicgo to next topic
本主題所含的標籤
無標籤
作者 [轉載]將 properties 做排列 [by cjsdn-frankwg] [精華]
browser

戀香

版主

發文: 3570
積分: 1
於 2003-07-18 12:49 user profilesend a private message to usersend email to browserreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
將 .prp 的 key 和 value 值
做排序的工作 ....

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package scrapbook;
 
import java.util.Properties;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Map;
import java.util.TreeMap;
import java.util.Iterator;
 
public class OrderedProperties {
 
    public static void main(String[] args) {
        Properties prop = new Properties();
        try {
            prop.load(new FileInputStream("test.properties"));
        }
        catch (IOException ex) {
            System.out.println("I/O Error!!! Probably \"test.properties\" not found.");
        }
 
        Map orderedProp = new TreeMap(prop);
 
        Iterator itr = orderedProp.entrySet().iterator();
        while (itr.hasNext()) {
            Map.Entry entry = (Map.Entry) itr.next();
            System.out.println(entry.getKey() + "=" + entry.getValue());
        }
    }
}


ps.有興趣的人 . 可以 try try 看 .. 呵 . 我還沒有 try 過 ...
所以不能保証一定可以 work ...


reply to postreply to post
作者 Re:[轉載]將 properties 做排列 [by cjsdn-frankwg] [Re:browser]
rexx





發文: 37
積分: 3
於 2003-07-21 15:20 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
我無聊試了一下, 可以!

用 jdk 的 font.properties , 結果像這樣...

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
C:\temp>java OrderedProperties
default.char=2751
dialog.0=Arial,ANSI_CHARSET
dialog.1=WingDings,SYMBOL_CHARSET
dialog.2=Symbol,SYMBOL_CHARSET
dialog.bold.0=Arial Bold,ANSI_CHARSET
dialog.bold.1=WingDings,SYMBOL_CHARSET
dialog.bold.2=Symbol,SYMBOL_CHARSET
dialog.bolditalic.0=Arial Bold Italic,ANSI_CHARSET
dialog.bolditalic.1=WingDings,SYMBOL_CHARSET
dialog.bolditalic.2=Symbol,SYMBOL_CHARSET
dialog.italic.0=Arial Italic,ANSI_CHARSET
dialog.italic.1=WingDings,SYMBOL_CHARSET
dialog.italic.2=Symbol,SYMBOL_CHARSET
dialoginput.0=Courier New,ANSI_CHARSET
dialoginput.1=WingDings,SYMBOL_CHARSET
dialoginput.2=Symbol,SYMBOL_CHARSET
dialoginput.bold.0=Courier New Bold,ANSI_CHARSET
dialoginput.bold.1=WingDings,SYMBOL_CHARSET
dialoginput.bold.2=Symbol,SYMBOL_CHARSET
dialoginput.bolditalic.0=Courier New Bold Italic,ANSI_CHARSET
dialoginput.bolditalic.1=WingDings,SYMBOL_CHARSET
dialoginput.bolditalic.2=Symbol,SYMBOL_CHARSET
dialoginput.italic.0=Courier New Italic,ANSI_CHARSET
dialoginput.italic.1=WingDings,SYMBOL_CHARSET
dialoginput.italic.2=Symbol,SYMBOL_CHARSET
exclusion.dialog.0=0500-20ab,20ad-ffff
exclusion.dialoginput.0=0500-20ab,20ad-ffff
exclusion.monospaced.0=0500-20ab,20ad-ffff
exclusion.sansserif.0=0500-20ab,20ad-ffff
exclusion.serif.0=0500-20ab,20ad-ffff
filename.Arial=ARIAL.TTF
filename.Arial_Bold=ARIALBD.TTF
filename.Arial_Bold_Italic=ARIALBI.TTF
filename.Arial_Italic=ARIALI.TTF
filename.Courier_New=COUR.TTF
filename.Courier_New_Bold=COURBD.TTF
filename.Courier_New_Bold_Italic=COURBI.TTF
filename.Courier_New_Italic=COURI.TTF
filename.Symbol=SYMBOL.TTF
filename.Times_New_Roman=TIMES.TTF
filename.Times_New_Roman_Bold=TIMESBD.TTF
filename.Times_New_Roman_Bold_Italic=TIMESBI.TTF
filename.Times_New_Roman_Italic=TIMESI.TTF
filename.WingDings=WINGDING.TTF
fontcharset.dialog.0=sun.io.CharToByteCp1252
fontcharset.dialog.1=sun.awt.windows.CharToByteWingDings
fontcharset.dialog.2=sun.awt.CharToByteSymbol
fontcharset.dialoginput.0=sun.io.CharToByteCp1252
fontcharset.dialoginput.1=sun.awt.windows.CharToByteWingDings
fontcharset.dialoginput.2=sun.awt.CharToByteSymbol
fontcharset.monospaced.0=sun.io.CharToByteCp1252
fontcharset.monospaced.1=sun.awt.windows.CharToByteWingDings
fontcharset.monospaced.2=sun.awt.CharToByteSymbol
fontcharset.sansserif.0=sun.io.CharToByteCp1252
fontcharset.sansserif.1=sun.awt.windows.CharToByteWingDings
fontcharset.sansserif.2=sun.awt.CharToByteSymbol
fontcharset.serif.0=sun.io.CharToByteCp1252
fontcharset.serif.1=sun.awt.windows.CharToByteWingDings
fontcharset.serif.2=sun.awt.CharToByteSymbol
inputtextcharset=ANSI_CHARSET
monospaced.0=Courier New,ANSI_CHARSET
monospaced.1=WingDings,SYMBOL_CHARSET
monospaced.2=Symbol,SYMBOL_CHARSET
monospaced.bold.0=Courier New Bold,ANSI_CHARSET
monospaced.bold.1=WingDings,SYMBOL_CHARSET
monospaced.bold.2=Symbol,SYMBOL_CHARSET
monospaced.bolditalic.0=Courier New Bold Italic,ANSI_CHARSET
monospaced.bolditalic.1=WingDings,SYMBOL_CHARSET
monospaced.bolditalic.2=Symbol,SYMBOL_CHARSET
monospaced.italic.0=Courier New Italic,ANSI_CHARSET
monospaced.italic.1=WingDings,SYMBOL_CHARSET
monospaced.italic.2=Symbol,SYMBOL_CHARSET
sansserif.0=Arial,ANSI_CHARSET
sansserif.1=WingDings,SYMBOL_CHARSET
sansserif.2=Symbol,SYMBOL_CHARSET
sansserif.bold.0=Arial Bold,ANSI_CHARSET
sansserif.bold.1=WingDings,SYMBOL_CHARSET
sansserif.bold.2=Symbol,SYMBOL_CHARSET
sansserif.bolditalic.0=Arial Bold Italic,ANSI_CHARSET
sansserif.bolditalic.1=WingDings,SYMBOL_CHARSET
sansserif.bolditalic.2=Symbol,SYMBOL_CHARSET
sansserif.italic.0=Arial Italic,ANSI_CHARSET
sansserif.italic.1=WingDings,SYMBOL_CHARSET
sansserif.italic.2=Symbol,SYMBOL_CHARSET
serif.0=Times New Roman,ANSI_CHARSET
serif.1=WingDings,SYMBOL_CHARSET
serif.2=Symbol,SYMBOL_CHARSET
serif.bold.0=Times New Roman Bold,ANSI_CHARSET
serif.bold.1=WingDings,SYMBOL_CHARSET
serif.bold.2=Symbol,SYMBOL_CHARSET
serif.bolditalic.0=Times New Roman Bold Italic,ANSI_CHARSET
serif.bolditalic.1=WingDings,SYMBOL_CHARSET
serif.bolditalic.2=Symbol,SYMBOL_CHARSET
serif.italic.0=Times New Roman Italic,ANSI_CHARSET
serif.italic.1=WingDings,SYMBOL_CHARSET
serif.italic.2=Symbol,SYMBOL_CHARSET


reply to postreply to post
作者 Re:[轉載]將 properties 做排列 [by cjsdn-frankwg] [Re:rexx]
browser

戀香

版主

發文: 3570
積分: 1
於 2003-07-21 15:25 user profilesend a private message to usersend email to browserreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
rexx 兄 ...
Good ~~ I like U ~~ Big Smile


reply to postreply to post
作者 Re:[轉載]將 properties 做排列 [by cjsdn-frankwg] [Re:browser]
annhy

來呦~



發文: 45
積分: 2
於 2003-07-25 15:44 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
加點解釋好了...

1
  Properties prop = new Properties();


Map <- Hashtable <- Properties
所以 Properties 可以當成 TreeMap() 的引數

1
  Map orderedProp = new TreeMap(prop);


SortedMap <- TreeMap
所以 TreeMap 一建立起來,就已經排序好了

1
2
3
4
5
        Iterator itr = orderedProp.entrySet().iterator();
        while (itr.hasNext()) {
            Map.Entry entry = (Map.Entry) itr.next();
            System.out.println(entry.getKey() + "=" + entry.getValue());
        }


依序印出資料


reply to postreply to post
» JWorld@TW »  Java 技巧文件

reply to topicthreaded modego to previous topicgo to next topic
  已讀文章
  新的文章
  被刪除的文章
Jump to the top of page

JWorld@TW 本站商標資訊

Powered by Powerful JuteForum® Version Jute 1.5.8