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)
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)
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
#Sun Jan 13 10:59:58 CST 2008 这个时间总是被写入还有前面的 # 号也会别写入写内容的时候怎样不把这个写进去呢
#Sun Jan 13 10:59:58 CST 2008
现在取 Name 的值取不到了
#Sun Jan 13 10:59:58 CST 2008 这个时间总是被写入 还有前面的 # 号也会被写入 写内容的时候怎样不把这个写进去呢
Properties p = new Properties();
p.setProperty("Name", "web7715367");
p.setProperty("Name2", "web7715368");
OutputStream os = new FileOutputStream("ini.ini");
p.store(os, null);
os.close();
}