Open a file for write with a servlet

How can you open a file (e.g . a Word file) for write with a servlet. The code below opens it for read.
public void dispatch(HttpServletRequest req,
            HttpServletResponse resp) throws IOException,URISyntaxException {
        String filenameToMakeWriteable = dispatchFile.getAbsolutePath();
        FileInputStream in=new FileInputStream(filenameToMakeWriteable);
        byte[] buffer=new byte[1024];
        int count=0;
        OutputStream out=   resp.getOutputStream();

Open in new window

Who is Participating?
Use a FileOutputStream.
What is it you are trying to achieve?

Hava a look here you need a FileOutputStream instead of a FileInputStream:
grandpalAuthor Commented:
A servlet is called with some args which the servlet interpretes and which leads to the display of a file. The code shown displays the file, but if its is a Word file, for example, you cannot use the save command inside Word to save changes to the file. One possible solution is  return a "file:" - url . I guess I then have to map file so it is accessible  the servlet context root. Any other solution ?
not really, if you're saving it with word it needs access to the file

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.