KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > comanche > FileRequestHandler


1 package comanche;
2 import java.io.*;
3
4 public class FileRequestHandler implements RequestHandler {
5   public void handleRequest (Request r) throws IOException {
6     File f = new File(r.url);
7     if (f.exists() && !f.isDirectory()) {
8       InputStream is = new FileInputStream(f);
9       byte[] data = new byte[is.available()];
10       is.read(data);
11       is.close();
12       r.out.print("HTTP/1.0 200 OK\n\n");
13       r.out.write(data);
14     } else {
15       throw new IOException("File not found");
16     }
17   }
18 }
19
Popular Tags