/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package cn.ac.bcc.action;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Properties;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.io.File;
/**
*
* @author hou
*/
public class ReadProperties {
Properties props = new Properties();
FileInputStream fis;
public String read(String url, String key) {
Properties p = new Properties();
String value = "";
try {
fis = new FileInputStream(new File(url));
p.load(fis);
value = p.getProperty(key);
} catch (FileNotFoundException ex) {
System.out.println("额额文件不存在..");
Logger.getLogger(ReadProperties.class.getName()).log(Level.SEVERE, null, ex);
} catch (IOException ie) {
} finally {
try {
fis.close();
} catch (IOException ex) {
Logger.getLogger(ReadProperties.class.getName()).log(Level.SEVERE, null, ex);
}
}
return value;
}
public static void main(String[] args) {
ReadProperties r = new ReadProperties();
System.out.println(r.read("D:/test.properties", "name"));
}
}