This code transmits the contents of a file to the other side of a netwok connection by copying the file byte-by-byte to the socket's output stream. Here, "file" is a variable of type File that refers to the file, and "socket" is a variable of type Socket that represents the network connection: InputStream fileIn = new FileInputStream(file); OutputStream socketOut = socket.getOutputStream(); while (true) { int x = fileIn.read(); // read one byte from file if (x < 0) break; // end of file reached socketOut.write(x); // write the byte to the socket } This code defines a function getMimeType(fileName) that returns a mime type for the function based on the file extension at the end of the file name. If the file name does not include an extension, or if no mime type is known for the file's extension, then the return value is null: private static String[][] mimeTypeMap = { { "txt", "text/plain" }, { "html", "text/html" }, { "htm", "text/html" }, { "css", "text/css" }, { "java", "text/x-java" }, { "jpeg", "image/jpeg" }, { "jpg", "image/jpeg" }, { "png", "image/png" }, { "gif", "image/gif" }, { "ico", "image/x-icon" }, { "class", "application/java-vm" }, { "jar", "application/java-archive" }, { "zip", "application/zip" }, { "xml", "application/xml" }, { "xhtml", "application/xhtml+xml" } }; private static String getMimeType(String fileName) { int pos = fileName.lastIndexOf('.'); if (pos < 0) return null; String ext = fileName.substring(pos+1).toLowerCase(); for (int i = 0; i < mimeTypeMap.length; i++) { if (mimeTypeMap[i][0].equals(ext)) return mimeTypeMap[i][1]; } return null; }