FileDocCategorySizeDatePackage
WastedConversions.javaAPI DocExample1033Fri Feb 21 13:10:52 GMT 2003None

WastedConversions

public class WastedConversions extends HttpServlet

Fields Summary
String
name
Constructors Summary
Methods Summary
public voiddoGet(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res)


       
                                  

    String file = getServletContext().getRealPath(name);

    res.setContentType("text/plain");
    PrintWriter out = res.getWriter();

    returnFile(file, out);
  
public static voidreturnFile(java.lang.String filename, java.io.Writer out)

    Reader in = null;
    try {
      in = new BufferedReader(new FileReader(filename));
      char[] buf = new char[4 * 1024];  // 4K char buffer
      int charsRead;
      while ((charsRead = in.read(buf)) != -1) {
        out.write(buf, 0, charsRead);
      }
    }
    finally {
      if (in != null) in.close();
    }