/////// FileServer.java /////// import java.io.*; import java.net.*; import java.util.StringTokenizer; public class FileServer { public static void main (String[] args) throws IOException { String filename, rw, dir = "/tmp/"; BufferedReader in = new BufferedReader( new InputStreamReader(System.in)); String line = in.readLine(); StringTokenizer tk = new StringTokenizer(line, " \t=&"); int c = tk.countTokens(); if ( c != 4 ) return; filename = tk.nextToken(); if ( filename.equals("filename") ) filename = tk.nextToken(); else return; rw = tk.nextToken(); if ( rw.equals("mode") ) rw = tk.nextToken(); else return; line = in.readLine(); if ( line.equals("") ) { if ( rw.equals("r") ) { readBack(dir + filename); return; } else { writeTo(dir + filename); return; } } } static void readBack(String file) throws IOException { int c; FileInputStream infile = new FileInputStream(file); while ( (c = infile.read() ) > -1 ) System.out.write(c); } static void writeTo(String file) throws IOException { int c; FileOutputStream ofile = new FileOutputStream(file); while ( (c = System.in.read() ) > -1 ) ofile.write(c); } }