黑马程序员技术交流社区
标题:
关于Properties的顺序问题
[打印本页]
作者:
thoris
时间:
2015-5-19 22:44
标题:
关于Properties的顺序问题
看到第20天 13课的 properties内容
主要代码如下
public class H_11Properties {
public static void main(String[] args) throws IOException {
//setAndGet();
method_1();
loadDemo();
}
public static void loadDemo() throws IOException
{
Properties prop=new Properties();
FileInputStream fis=new FileInputStream("info.txt");
//将流中的数据加载进集合
prop.load(fis);
sop(prop);
prop.list(System.out);
}
public static void method_1() throws IOException
{
BufferedReader bufr=new BufferedReader(new FileReader("info.txt"));
String line=null;
Properties prop=new Properties();
while((line=bufr.readLine())!=null)
{
//sop(line);
String[] arr=line.split("=");
//sop(arr[0]+" "+arr[1]);
prop.setProperty(arr[0], arr[1]);
//顺序按照哈希表
}
bufr.close();
sop(prop);
}
后面还有sop那个
复制代码
info.txt文档里面的内容是随便打的,具体如下
zhangsan=34
zaijian=hha
李四=hah
duqu=78
hett=http
主函数调用了两个方法:
method_1();
loadDemo();//这里面有两个打印动作
结果是这样:
{duqu=78, hett=http, zaijian=hha, zhangsan=34, 李四=hah}
{duqu=78, ????=hah, hett=http, zaijian=hha, zhangsan=34}
-- listing properties --
duqu=78
????=hah
zaijian=hha
hett=http
zhangsan=34
顺序和原文本不同还可以理解,但是为什么三种打印方式的输出顺序都不一样?
作者:
thoris
时间:
2015-5-19 22:50
其中的问号是因为用字节流读了字符的缘故,改用转换流的话,
method_1的结果和loadDemo的sop(prop)是一样的
但是和prop.list(System.in) 还是不一样
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2