在Eclipse中Servlet读取项目配置文件

来源:互联网 发布:淘宝 atlas插件框架 编辑:程序博客网 时间:2024/05/29 19:58

代码:

JSONObject config = new JSONObject(IOUtils.readString(request.getServletContext().getResourceAsStream("/WEB-INF/conf/update0.conf")));

其中,配置文件update0.conf放在"/WEB-INF/conf"下,内容如下:

{"version_code":2,"description":"album_mobile"}

IOUtils如下:

public class IOUtils {public static String readString(InputStream is) {ByteArrayOutputStream baos = new ByteArrayOutputStream();byte[] b = new byte[500];int temp = 0;try {while((temp = is.read(b, 0, 500)) != -1) {baos.write(b, 0, temp);}} catch (IOException e) {e.printStackTrace();}return new String(baos.toByteArray());}}


原创粉丝点击