FileDocCategorySizeDatePackage
WriteFileServlet.javaAPI DocExample807Tue Jul 01 09:55:00 BST 2003com.oreilly.tomcat.servlets

WriteFileServlet

public class WriteFileServlet extends GenericServlet

Fields Summary
Constructors Summary
Methods Summary
public voidservice(javax.servlet.ServletRequest request, javax.servlet.ServletResponse response)

        // Try to open a file and write to it.
        String catalinaHome = "/usr/local/jakarta-tomcat-4.1.24";
        File testFile = new File(catalinaHome + "/webapps/ROOT", "test.txt");
        FileOutputStream fileOutputStream = new FileOutputStream(testFile);
        fileOutputStream.write(new String("testing...").getBytes());
        fileOutputStream.close();

        // If we get down this far, the file was created successfully.
        PrintWriter out = response.getWriter();
        out.println("File created successfully!");