package main;
import java.io.*;
import java.net.InetSocketAddress;
import com.sun.net.httpserver.HttpExchange;
import com.sun.net.httpserver.HttpHandler;
import com.sun.net.httpserver.HttpServer;
public class Main {
public static void main(String[] args) throws Exception {
HttpServer server = HttpServer.create(new InetSocketAddress(80), 0);
server.createContext("/Hello", new MyHandler());
server.start();
}
static class MyHandler implements HttpHandler {
public void handle(HttpExchange t) throws IOException {
File f = new File("c:/A.jpg");
FileInputStream fs = new FileInputStream("c:/A.jpg");
byte[] b = new byte[(int) f.length()];
fs.read(b);
t.sendResponseHeaders(200, b.length);
OutputStream os = t.getResponseBody();
os.write(b);
os.close();
}
}
}
留言列表