这样可以在classpath里修改controlSetup.properties文件的值,而直接在程序里使用。
通过getResourceAsStream方式载入的文件被Cache.
public InputStream getpro()
{
String propersetupfile="com/resources/controlSetup.properties";
String dir=this.getServlet().getServletContext().getRealPath("/");
System.out.println("real directory:"+dir);
String pdir=dir+"WEB-INF/classes/"+propersetupfile;
System.out.println("properties file in:"+pdir);
InputStream fi=null;
try
{
fi=new FileInputStream(pdir);
}catch(Exception e)
{
e.printStackTrace();
fi= this.getClass()
.getClassLoader()
.getResourceAsStream(propersetupfile);
}
return fi;
// return this.getClass()
// .getClassLoader()
// .getResourceAsStream(propersetupfile);
}
通过getResourceAsStream方式载入的文件被Cache.
public InputStream getpro()
{
String propersetupfile="com/resources/controlSetup.properties";
String dir=this.getServlet().getServletContext().getRealPath("/");
System.out.println("real directory:"+dir);
String pdir=dir+"WEB-INF/classes/"+propersetupfile;
System.out.println("properties file in:"+pdir);
InputStream fi=null;
try
{
fi=new FileInputStream(pdir);
}catch(Exception e)
{
e.printStackTrace();
fi= this.getClass()
.getClassLoader()
.getResourceAsStream(propersetupfile);
}
return fi;
// return this.getClass()
// .getClassLoader()
// .getResourceAsStream(propersetupfile);
}