求助中文乱码问题
我的代码如下
public class ZhanghaoLuru extends HttpServlet{
public void doGet(HttpServletRequest req ,HttpServletResponse resp)
throws ServletException,IOException{
resp.setCharacterEncoding("gb2312");
resp.setContentType("text/html;charset=utf-8");
String username=req.getParameter("username");
String password=req.getParameter("password");
String str = new String(username.getBytes("ISO-8859-1"),"UTF-8");
String information=str+","+password;
if(str!=null && password!=null){
resp.sendRedirect("success.html");
}
File javaFile = new File( "E:\\java\\shijiong.txt ");
try{
if(javaFile.isFile()){
System.out.println( "文件已存在! ");
}
else{
javaFile.createNewFile();
System.out.println( "文件创建成功! ");
}
String fileName = "E:\\java\\shijiong.txt";
appendMethodB(fileName, information);
}
catch (IOException e1) {
e1.printStackTrace();
}
}
public static void appendMethodB(String fileName, String content) throws IOException{
try {
FileWriter writer = new FileWriter(fileName, true);
writer.write(content);
writer.close();
}
catch (IOException e) {
e.printStackTrace();
}
}
public void doPost(HttpServletRequest req ,HttpServletResponse resp)
throws ServletException,IOException{
resp.setContentType("text/html;charset=gbk");
doGet(req,resp);
}
}
在页面输入英文没问题但是中文后在返回的TXT文档里出现的就是几个问号,不出汉字,是怎么回事,求大神帮忙解决一下,。