(Thanks Boma) import java.io.*; public class ShowDir { public static void main(String[] args) { File f = new File("."); try{ String directoryRoot = f.getCanonicalPath(); System.out.print("Directory root is: " + directoryRoot); }catch (Throwable e){e.printStackTrace();} } }
(Thanks Eric) private PrintStream out = null; [...] out.append("HTTP/1.1 200 OK\n"); out.append("Date: " + new Date() + "\n"); out.append("\n\n"); etc.and:
(Thanks John) static final byte[] EOL = {(byte) '\r', (byte) '\n'}; OutputStream out = new BufferedOutputStream(sock.getOutputStream()); PrintWriter prntout = new PrintWriter(new OutputStreamWriter(out), true); prntout.println("HTTP/1.1 200 OK"); prntout.println("Content-Length: " + thedata.length()); prntout.println("Content-type: " + ct); out.write(EOL);and:
(Thanks Kevin) private String outputData = "HTTP/1.1 200 OK" + "\r\n" + "Content-Length: " + "LENGTH" + "\r\n" + "Connection: CONNECTION" + "\r\n" + "DATATYPE" + "\r\n\r\n"; [Use stringval.replace(x.y) substitution for values determined at runtime]