81,092
社区成员
发帖
与我相关
我的任务
分享
BufferedReader br= null;
StringBuffer txt = new StringBuffer();
String path = 你的文件路径。
try {
URL url = new URL(path);
URLConnection connection = url.openConnection();
InputStream is = connection.getInputStream();
String s = "";
br = new BufferedReader(new InputStreamReader(is,"gb2312"));
while((s = br.readLine())!=null){
txt.append(s);
txt.append("\n");
}
String content = txt.toString();
req.setAttribute("content", content);
} catch (Exception e) {
e.printStackTrace();
req.setAttribute("errorMessage", "找不到正文文件!");
return "edit/common/error";
}finally{
if(br!=null){
try {
br.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}