81,115
社区成员
发帖
与我相关
我的任务
分享
public class Utils{
public static InputStream getInputStream(Class<?> basePathClazz,String resourceName) throws IOException {
return basePathClazz.getResource(resourceName).openStream();
}
}
获取输入流,读出来。
然后,写一个servlet,重载service方法
@Override
public void service(ServletRequest arg0, ServletResponse arg1)
throws ServletException, IOException {
InputStream is = Utils.getInputStream(getClass(), "");
byte[] buff = new byte[1024];
int count = is.read(buff);
StringBuilder result = new StringBuilder();
while(count>0) {
String string =new String(buff, 0, count);
result.append(string);
}
arg1.getWriter().write(result.toString());
}