我在 Servlet 里面 调用 另一个的 类的 IO 方法 创建 文件。 没有报错。 但是 没有 file 生成。
代码是很简单:java类:importjava.io.File;importjava.io.IOException;publicclassCreateFileTest{p...
代码是很简单:
java类:
import java.io.File;
import java.io.IOException;
public class CreateFileTest {
public void createFile() {
File file = new File("out.txt");
try {
file.createNewFile();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
servlet:
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
CreateFileTest file = new CreateFileTest();
file.createFile();
}
jsp:
<body>
<form action="ServletTest">
<input type="submit" value="submit">
</form>
</body> 展开
java类:
import java.io.File;
import java.io.IOException;
public class CreateFileTest {
public void createFile() {
File file = new File("out.txt");
try {
file.createNewFile();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
servlet:
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
CreateFileTest file = new CreateFileTest();
file.createFile();
}
jsp:
<body>
<form action="ServletTest">
<input type="submit" value="submit">
</form>
</body> 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询