(Thanks Trevor)
If having trouble with file name slashes tyr ".replace("\\", "/")"
(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]and: In THIS server you have to specify the directory where you will be serving files from. (In our server we use the location where the server was started.)
In Windows I used:
> java FileServer 3344 c:\Users\Elliottand
150 line web server may be of some background use.