下面是一个 servlet,它尝试在该目录中创建一个目录和一个文本文件。
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
String s = request.getServletContext().getRealPath("/");
PrintWriter out = response.getWriter();
FileMaker fm = new FileMaker();
fm.makeDirectoryTester();
}
在其中创建目录和文本文件的类:
public void makeDirectoryTester() {
try {
File f = new File("FlushTester/");
if(!f.exists()) {
boolean b = f.mkdir();
System.out.println("Directory Made (Inside makeDirectoryTester) --> " + b);
PrintWriter writer = new PrintWriter("FlushTester/TESTER.txt");
writer.println("This is the first statement");
writer.println("This is the second statement");
writer.println("This is the third statement");
writer.close();
}
}catch(Exception exc) {
exc.printStackTrace();
}
}
问题是布尔f.mkdir()返回true
但我看不到任何创建的目录或其中的任何文件!这是为什么 ?我使用tomcat作为服务器。这可能是什么原因?