try{
FileInputStream in = new FileInputStream("1.text");
Properties pro = new Properties();
pro.load(in);
Enumeration enum = pro.propertyNames();
while(enum.hasMoreElements())
{
String key = (String)enum.nextElement();
String value_url = pro.getProperty(key);
System.out.println("first"+key+"="+value_url);
}
in.close();
}
catch(Exception e)
{
e.printStackTrace();
}
这个怎么只输出1.text文件中的最后一行,好像也只得到最后一行
1.text内容:
#Fri Mar 28 18:14:28 CST 2008
25=http\://127.0.0.1\:8080/wal/3.jpg
#Fri Mar 28 18:14:28 CST 2008
25=http\://127.0.0.1\:8080/wal/2.jpg
#Fri Mar 28 18:14:28 CST 2008
25=http\://127.0.0.1\:8080/wal/1.jpg
这里面的也是读进去的。
请问各位高手怎么回事呀?
FileInputStream in = new FileInputStream("1.text");
Properties pro = new Properties();
pro.load(in);
Enumeration enum = pro.propertyNames();
while(enum.hasMoreElements())
{
String key = (String)enum.nextElement();
String value_url = pro.getProperty(key);
System.out.println("first"+key+"="+value_url);
}
in.close();
}
catch(Exception e)
{
e.printStackTrace();
}
这个怎么只输出1.text文件中的最后一行,好像也只得到最后一行
1.text内容:
#Fri Mar 28 18:14:28 CST 2008
25=http\://127.0.0.1\:8080/wal/3.jpg
#Fri Mar 28 18:14:28 CST 2008
25=http\://127.0.0.1\:8080/wal/2.jpg
#Fri Mar 28 18:14:28 CST 2008
25=http\://127.0.0.1\:8080/wal/1.jpg
这里面的也是读进去的。
请问各位高手怎么回事呀?
#Fri Mar 28 18:14:28 CST 2008
25=http\://127.0.0.1\:8080/wal/3.jpg
#Fri Mar 28 18:14:28 CST 2008
26=http\://127.0.0.1\:8080/wal/2.jpg
#Fri Mar 28 18:14:28 CST 2008
27=http\://127.0.0.1\:8080/wal/1.jpg
Properties内部其实用的也是HashMap
可以看jdk源码
Enumeration 只剩下一个元素楼主应该知道map是如何操作
#Fri Mar 28 18:14:28 CST 2008
25=http\://127.0.0.1\:8080/wal/3.jpg
#Fri Mar 28 18:14:28 CST 2008
26=http\://127.0.0.1\:8080/wal/2.jpg
#Fri Mar 28 18:14:28 CST 2008
27=http\://127.0.0.1\:8080/wal/1.jpg
经测试是可以的
附测试代码: public static void main(String[] args) throws FileNotFoundException, IOException{
Reader reader = null;
try {
reader = new FileReader("a.txt"); Properties properties = new Properties();
properties.load(reader);
Enumeration enumeration = properties.propertyNames();
while(enumeration.hasMoreElements()){
String key = enumeration.nextElement().toString();
System.out.println("key:"+key);
String value = properties.getProperty(key);
System.out.println("value:"+value);
}
} finally {
reader.close();
}
}
key:27
value:http://127.0.0.1:8080/wal/1.jpg
key:26
value:http://127.0.0.1:8080/wal/2.jpg
key:25
value:http://127.0.0.1:8080/wal/3.jpg