代码:
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());
}
}