I new with servlet programming and I am trying to create and write a file from following java method-
public void file() throws FileNotFoundException, UnsupportedEncodingException {
PrintWriter writer = new PrintWriter("the-file-name.txt", "UTF-8");
writer.println("The first line");
writer.println("The second line");
writer.close();
System.out.println("file created");
}
And I want to call it from servlet like this
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
TryMethod tryMethod = new TryMethod();
tryMethod.file();
}
can anyone suggest why it is not getting executed from servlet? This method gets called when called from the main method.
System.out.println
statement in your servlet is that getting executed ? Is your servlet 100% working ?Paths.get("").currentRelativePath.toAbsolutePath().toString()
- you will find them there.