package test;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Properties;
import java.util.Set;
/**
* 读取properties文件的内容,并返回map
*
* @author 1
*
*/
public class ReadProperties {
/**
* 文件路径
*/
private String filePath;
public ReadProperties() {
// TODO Auto-generated constructor stub
}
public ReadProperties(String path) {
this.filePath = path;
}
public static void main(String[] args) {
ReadProperties rp = new ReadProperties(
"E:\\workspace\\psf\\test\\config\\config.properties");
Map<String, String> map = new HashMap<String, String>();
System.out.println(map);
}
/**
* 获取properties文件中的内容,并返回map
*
* @return
*/
public Map<String, String> getProperties() {
Map<String, String> map = new HashMap<String, String>();
InputStream in = null;
Properties p = null;
try {
in = new BufferedInputStream(new FileInputStream(new File(
this.filePath)));
p.load(in);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Set<Entry<Object, Object>> entrySet = p.entrySet();
for (Entry<Object, Object> entry : entrySet) {
map.put((String) entry.getKey(), (String) entry.getValue());
}
return map;
}
public String getFilePath() {
return filePath;
}
public void setFilePath(String filePath) {
this.filePath = filePath;
}
}
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Properties;
import java.util.Set;
/**
* 读取properties文件的内容,并返回map
*
* @author 1
*
*/
public class ReadProperties {
/**
* 文件路径
*/
private String filePath;
public ReadProperties() {
// TODO Auto-generated constructor stub
}
public ReadProperties(String path) {
this.filePath = path;
}
public static void main(String[] args) {
ReadProperties rp = new ReadProperties(
"E:\\workspace\\psf\\test\\config\\config.properties");
Map<String, String> map = new HashMap<String, String>();
System.out.println(map);
}
/**
* 获取properties文件中的内容,并返回map
*
* @return
*/
public Map<String, String> getProperties() {
Map<String, String> map = new HashMap<String, String>();
InputStream in = null;
Properties p = null;
try {
in = new BufferedInputStream(new FileInputStream(new File(
this.filePath)));
p.load(in);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Set<Entry<Object, Object>> entrySet = p.entrySet();
for (Entry<Object, Object> entry : entrySet) {
map.put((String) entry.getKey(), (String) entry.getValue());
}
return map;
}
public String getFilePath() {
return filePath;
}
public void setFilePath(String filePath) {
this.filePath = filePath;
}
}