个人网站 创意,做网站内容来源,做ppt很有创意的网站,建设网站报价转载自 读取/书写Java的XML格式properties文件
在JDK5中#xff0c;properties文件的格式可以由XML构成#xff0c;这里给出了一个读取/书写XML格式properties文件的例子。因为使用了XML#xff0c;所以文件内容支持了CJKV(中文、日文、韩文、越南语)。可以直接书写、调用…转载自 读取/书写Java的XML格式properties文件
在JDK5中properties文件的格式可以由XML构成这里给出了一个读取/书写XML格式properties文件的例子。因为使用了XML所以文件内容支持了CJKV(中文、日文、韩文、越南语)。可以直接书写、调用。
例子代码
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Properties;
/*** * * author 郝春利* since 2008/09/11* version $Revision:$*/
public class PropertiesTest {/*** param args*/public static void main(String[] args) {// 书写properties文件Properties properties new Properties();properties.put(ONE, 1);properties.put(TWO, 2);properties.put(中文, 看看中文怎么样);properties.put(日本語, 日本語はどう);properties.put(한국어, 한국어);properties.put(Thảo luận tiếng Việt, Thảo luận tiếng Việt);OutputStream stream null;http://www.loveapple.cntry {stream new FileOutputStream(temp.xml);properties.storeToXML(stream, Temporary Properties);}catch (IOException ex) {ex.printStackTrace();}finally{try{stream.close();}catch(Exception e){}}// 读取properties文件Properties properties2 new Properties();InputStream is null ;try{is new FileInputStream(temp.xml);properties2.loadFromXML(is);System.out.println(properties2);}catch (IOException e) {e.printStackTrace();}finally{try{is.close();}catch (Exception e) {}}}
}输出结果
?xml version1.0 encodingUTF-8 standaloneno?
!DOCTYPE properties SYSTEM http://java.sun.com/dtd/properties.dtd
properties
commentTemporary Properties/comment
entry keyTWO2/entry
entry keyONE1/entry
entry key한국어한국어/entry
entry keyThảo luận tiếng ViệtThảo luận tiếng Việt/entry
entry key日本語日本語はどう/entry
entry key中文看看中文怎么样/entry
/properties