前提:文件中的内容是key=value方式的
两种方式:本地文件和远程资源文件
1、将本地文件以流的方式写入java properties(map)对象中:
File tempFile = new File("d:\\a.txt");
Properties prop = null;
try {
InputStream reader = new FileInputStream(tempFile);
BufferedReader br = new BufferedReader(
new InputStreamReader(reader));
prop = new Properties();
prop.load(br);
br.close();
br = null;
} catch (MalformedURLException mue) {
mue.printStackTrace();
} catch (IOException ioe) {
ioe.printStackTrace();
}
2、将URL指定文件以流的方式写入java properties(map)对象中:
String strDownloadFileUrl = "http://localhost:8080/abc/a.txt"
URL resource = null;
Properties prop = null;
try {
resource = new URL(strDownloadFileUrl);
InputStream is = resource.openStream();
BufferedReader br = new BufferedReader(new InputStreamReader(is));
prop = new Properties();
prop.load(br);
br.close();
br = null;
} catch (MalformedURLException mue) {
mue.printStackTrace();
} catch (IOException ioe) {
ioe.printStackTrace();
}
两种方式:本地文件和远程资源文件
1、将本地文件以流的方式写入java properties(map)对象中:
File tempFile = new File("d:\\a.txt");
Properties prop = null;
try {
InputStream reader = new FileInputStream(tempFile);
BufferedReader br = new BufferedReader(
new InputStreamReader(reader));
prop = new Properties();
prop.load(br);
br.close();
br = null;
} catch (MalformedURLException mue) {
mue.printStackTrace();
} catch (IOException ioe) {
ioe.printStackTrace();
}
2、将URL指定文件以流的方式写入java properties(map)对象中:
String strDownloadFileUrl = "http://localhost:8080/abc/a.txt"
URL resource = null;
Properties prop = null;
try {
resource = new URL(strDownloadFileUrl);
InputStream is = resource.openStream();
BufferedReader br = new BufferedReader(new InputStreamReader(is));
prop = new Properties();
prop.load(br);
br.close();
br = null;
} catch (MalformedURLException mue) {
mue.printStackTrace();
} catch (IOException ioe) {
ioe.printStackTrace();
}