Here you can find the source of writeFile(String path, OutputStream out)
public static void writeFile(String path, OutputStream out) throws IOException
//package com.java2s; /**// w w w .ja v a2s .co m * License * * Licensed under the GNU GPL v3 * http://www.gnu.org/licenses/gpl.html * */ import java.io.BufferedInputStream; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.OutputStream; public class Main { public static void writeFile(String path, OutputStream out) throws IOException { File file = new File(path); if (file.exists() && !file.isDirectory()) { out.write(("HTTP/1.1 200 OK" + "\r\n" + "Content-Type: text/html" + "\r\n" + "Content-Length: " + file.length() + "\r\n" + "\r\n").getBytes()); BufferedInputStream in = new BufferedInputStream(new FileInputStream(file)); while (true) { int data = in.read(); if (data == -1) break; out.write(data); } in.close(); } else { String ct = "400 - NOT FIND! \r\n PATH : " + path; out.write(("HTTP/1.1 400 NOT FIND" + "\r\n" + "Content-Type: text/html" + "\r\n" + "Content-Length: " + ct.getBytes("iso-8859-1") + "\r\n" + "\r\n").getBytes()); out.write(ct.getBytes()); } out.flush(); } }