JSP

初学JSP,在保存文件到txt的时候出现了问题。 以下是保存文件的代码: ` String Msg = “姓名:” + Name + “ Email: “


"; String path = request.getRealPath("/message"); out.println(path); try { FileWriter fw = new FileWriter(path + "/message.txt", true); BufferedWriter bw = new BufferedWriter(fw); bw.write(Msg); bw.flush(); bw.close(); fw.close(); } catch(Exception e) { out.println(e.getMessage()); } 报错这一行出了问题:FileWriter fw = new FileWriter(path + “/message.txt”, true); 解决方法:将String path = request.getRealPath(“.”);改为String path = request.getRealPath(“/message”); 因为我是在虚拟目录下的message目录运行程序的,而“.”代表根目录。