java Properties问题

cooc123 2008-01-12 06:14:36
public String readValue(String filePath, String key) {
Properties props = new Properties();
{
InputStream in = new BufferedInputStream(new FileInputStream(filePath));
System.out.println(in);
props.load(in);
String value = props.getProperty(key);
System.out.println(key + value);
return value;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}

public static void main(String[] args) {
t ts = new t();
ts.readValue("ini.ini", "key");
}

当ini.ini 里只有一行数据的时候,没问题

当有多行数据的时候就出问题了

java.lang.IllegalArgumentException: Malformed \uxxxx encoding.
at java.util.Properties.loadConvert(Unknown Source)
at java.util.Properties.load0(Unknown Source)
at java.util.Properties.load(Unknown Source)
at org.test.t.readValue(t.java:16)
at org.test.t.main(t.java:28)
...全文
220 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
时间写入那是默认的自动写进去的,用Properties写入时不能取消的。

若不想要这个时间,可以采用HashMap或者其他的Map写入文件就可以了。
  • 打赏
  • 举报
回复
public static void main(String[] args) throws IOException {
Properties p = new Properties();
p.setProperty("Name", "web7715367");
p.setProperty("Name2", "web7715368");
OutputStream os = new FileOutputStream("ini.ini");
p.store(os, null);
os.close();
}
token1984 2008-02-13
  • 打赏
  • 举报
回复
mark
cooc123 2008-02-12
  • 打赏
  • 举报
回复
#Name=web7715367
#Sun Jan 13 10:59:58 CST 2008 这个时间总是被写入

还有前面的 # 号也会被写入

写内容的时候怎样不把这个写进去呢
Jermaine 2008-01-16
  • 打赏
  • 举报
回复
完全可以执行的代码啊。。。。。。
大海Online 2008-01-16
  • 打赏
  • 举报
回复
用记事本打开, 删掉
cooc123 2008-01-14
  • 打赏
  • 举报
回复
........................
baobeiSimple 2008-01-13
  • 打赏
  • 举报
回复
#,这个符号是注释,相当于Java中的 //
cooc123 2008-01-13
  • 打赏
  • 举报
回复
#Name=web7715367
#Sun Jan 13 10:59:58 CST 2008


现在取 Name 的值取不到了
cooc123 2008-01-13
  • 打赏
  • 举报
回复


#Name=web7715367
#Sun Jan 13 10:59:58 CST 2008 这个时间总是被写入

还有前面的 # 号也会别写入

写内容的时候怎样不把这个写进去呢
cooc123 2008-01-13
  • 打赏
  • 举报
回复
可怎样不让他把这个符号 写进去呢,,,,,,,,,,,
action_520_12 2008-01-12
  • 打赏
  • 举报
回复

package cn.csu.edu.collection.vo;

import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.InputStream;
import java.util.Properties;

public class TestIni {
public String readValue(String filePath, String key) {
Properties props = new Properties();
try {
InputStream in = new BufferedInputStream(new FileInputStream(filePath));
System.out.println(in);
props.load(in);
String value = props.getProperty(key);
System.out.println(key + value);
return value;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
TestIni ts = new TestIni();
ts.readValue("ini.ini", "qq");
}
}



我的ini文件的内容:
#my properties
#Sat Jan 12 20:57:32 CST 2008
qq=37245900
user=makai
pw=123456
action_520_12 2008-01-12
  • 打赏
  • 举报
回复
没问题啊

62,623

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧