巧妙装载你的properties

详细的,请访问 这里

好几种方式装载 resource 文件:

1. File via FileInputStream, FileReader, and RandomAccessFile)

你需要计算文件路径,是否是绝对的或相对的。所以这样做将使你的程序不易移植.

2. ClassLoader.getResourceAsStream (”some/pkg/resource.properties”);

以斜线分割包,路径是绝对的。

3. Class.getResourceAsStream (”/some/pkg/resource.properties”);

以斜线分割包,路径可以是绝对的或相对的.
4. ResourceBundle.getBundle (”some.pkg.resource”);

以点分割包,.properties 是隐含的,因为bundle可以是一个类。

By javafuns on May 12, 2006 at 10:44 · Views: 892 · Permalink · RSS
Categorized in: Java · Tagged with: 
1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading ... Loading ...

One Response

Subscribe to comments via RSS

  1. Written by Java 中的 Properties | Open your thoughts
    on 2009/11/18 at 22:10
    Reply · Permalink

    [...] 另外请参考《巧妙装载你的properties》 [...]

Subscribe to comments via RSS

Leave a Reply


  • Highest Rated

  • My PicasaPhotos

    IMG_0615.JPG

    991e9e6688739d37aa184c38.jpg

    IMG_0694.JPG

  • RSS My del.icio.us

  • My RSS