public class ExcelUtil extends HttpServlet {
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
ServletContext sc = this.getServletContext();
System.out.print(sc.getRealPath("result.txt"));
writeFile(sc.getRealPath("result.txt"), "123");
}
public void writeFile(String writepath, String excelcontent) {
File file = new File(writepath);
FileWriter fw;
try {
fw = new FileWriter(file, true);
fw.write(excelcontent);
fw.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
我把result.txt放到了WEB-INF下但是不能正常写入,不知道什么原因,可能是因为路径写错了吧,谢谢帮助啊。