用指定的字条集编码读取文件内容

<%@ page language="java" pageEncoding="UTF-8"%>
<%@ page import="java.io.*"%>

<%
request.setCharacterEncoding("utf-8");
response.setContentType("application/vnd.symbian.install");
response.setCharacterEncoding("UTF-8");
String str = getServletContext().getRealPath("/");  //D:\Tomcat 5.5\webapps\pingoe\
String name = request.getParameter("name");
String pw = request.getParameter("pw");
if (name != null && name.trim().equals("hello")
    && pw != null && pw.trim().equals("123")){
    //out.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
   // + "<response cmd=\"restore\" ret=\"0\">");
} else {
out.println("<response cmd=\"restore\" ret=\"-1\"/>");
return;
}


String strContent = "";
String path = str + "uploadUdx\\86aaa6ca86c7b299ee7cd22c4eef5102.udx";
InputStreamReader read = null;
BufferedReader reader = null;
try {
read = new InputStreamReader (new FileInputStream(path),"UTF-8");
reader = new BufferedReader(read);
String line;
//StringBuffer context = new StringBuffer();
while ((line = reader.readLine()) != null) {
strContent+=line;
  strContent+="\n";
}

System.out.println("strContent: " + strContent);
//out.println(strContent + "</response>");
out.println(strContent);
} catch (Exception e) {
} finally {
//最后要在finally中将reader对象关闭
if (reader != null) {
try {
reader.close();
} catch (Exception e) {
e.printStackTrace();
}
}
if(read != null){
try{
read.close();
}catch(Exception e){
e.printStackTrace();
}
}
File file = new File(path);
file.delete();
}
out.flush();
out.close();
%>

你可能感兴趣的:(tomcat,xml,Symbian)