import java.io.File;
import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
public class TestPorpert
{
/** <一句话功能简述>
* <功能详细描述>
* @param args
* @see [类、类#方法、类#成员]
*/
static String path = "/test.properties";
public static void main(String[] args)
{
// TODO Auto-generated method stub
String content = null;
File fileName = new File(path);
BufferedInputStream in=null;
if (fileName.exists())
{
System.out.println("该文件存在!");
}
try
{
in = new BufferedInputStream(new FileInputStream(fileName));
// in = new FileInputStream(fileName);
// while((content = bf.readLine()) != null)
// {
// System.out.println(content);
// }
}
catch (Exception e1)
{
// TODO Auto-generated catch block
e1.printStackTrace();
}
Properties props = new Properties();
// InputStream in = AdminConfig.class.getResourceAsStream(path); 此方法只访问相对路径,即classes下的文件。
// if (in == null)
// {
// in = Thread.currentThread()
// .getContextClassLoader()
// .getResourceAsStream(path);
// System.out.println(path);
// }
try
{
props.load(in);
}
catch (IOException e)
{
System.out.println(e);
}
finally
{
if (null != in)
{
try
{
in.close();
}
catch (IOException e)
{
System.out.println(e);
}
}
}
// 打印值
System.out.println(props.getProperty("a"));
}
}