public static void main(String[] args) {
        try {
            String contentType = "text/plain";
            if (args[0].endsWith(".html") || args[0].endsWith(".htm"))
                contentType = "text/html";

            InputStream in = new FileInputStream(args[0]);
            ByteArrayOutputStream out = new ByteArrayOutputStream();
            int b;

            while ((b = in.read()) != -1)
                out.write(b);

            byte[] data = out.toByteArray();

            //设置监听端口
            int port;
            try {
                port = Integer.parseInt(args[1]);
                if (port < 1 || port > 65535)
                    port = 80;
            } catch (Exception e) {
                port = 80;
            }

            String encoding = "ASCII";
            if (args.length > 2)
                encoding = args[2];

            Thread t = new SingleFileHTTPServer(data, encoding, contentType, port);
            t.start();

        } catch (ArrayIndexOutOfBoundsException e) {
            System.out.println("Usage:java SingleFileHTTPServer filename port encoding");
        } catch (Exception e) {
            System.err.println(e);// TODO: handle exception
        }
    }