tomcatでファイルの入出力ができません
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
doGet(request, response);
String body = request.getParameter("body");
body = new String(body.getBytes("SJIS"), "SJIS");
response.setContentType("text/html;charset=Shift_JIS");
PrintWriter out = response.getWriter();
out.print("<html><head><title>tt</title></head><body>");
//out.print(body);
String path = getServletContext().getRealPath("/WEB-INF/sample.txt");
try{
BufferedWriter bw = new BufferedWriter(new FileWriter(path,true)); bw.write(body); bw.newLine(); bw.close(); out.print("成功"); }catch(IOException e){ out.print("失敗"); } BufferedReader br = new BufferedReader(new FileReader(path)); // out.print("</body></html>"); out.close(); }
}
eclipseを使っています
WEB-INF配下にsample.txtをおいていますが出力も入力もうまく行きません
一応、成功という文字は出ます
原因と対処法を教えてください
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。