I've the below project structure in my eclipse.
and my code in servlet is as below.
File entityFile = new File(getServletContext().getContextPath() + "/EntityList/entities.txt");
FileWriter fout = new FileWriter(entityFile);
fout.write("The Content");
fout.close();
here basically I'm trying to write to a file available at /EntityList/entities.txt
, but when I run this, I get the exception as below.
SEVERE: Servlet.service() for servlet [com.luis.servlets.WriteEntityToAFile] in context with path [/LUISWebUI] threw exception java.io.FileNotFoundException: \LUISWebUI\EntityList\entities.txt (The system cannot find the path specified)
I know that I'm going wrong with the path, Can someone please put me in the right direction.
Update
Apologies for the confusion.
I'm sending some data from jsp to servlet to write to the entities.txt
file. I'm able to capture it in servlet(Cross checked it by doing sysout).