// a test applet to show the use of the Linlyn class // you don't have to embed the passwd in the code - you could // prompt for it. // import java.awt.*; // needed by the applet import java.applet.*; import java.io.*; // needed by Linlyn import java.net.*; import java.util.*; public class myAppletOutput3Client extends Applet { public void init() { try { setBackground(Color.yellow); // upload to file // In general: // Linlyn u = new Linlyn("YOUR_SERVER", "USERNAME", "PASSWD"); Linlyn u = new Linlyn("jazzy.mcs.csuhayward.edu", "grewe", "b1utch"); // u.upload(".", "dataOutput.dat", //This is if you wanted to write once // "'Hello -line1 \n" + // "line 2 \n" + // "line 3 \n "); //assumes file already exists and you are appending to it //file is called dataOutput.dat and is in the same directory //as this code u.append("public_html/CS3520/Mat/AppletIO", "dataOut3Client.dat", "'Hello -line1 \n" + "line 2 \n" + "line 3 \n ", true); // add some more onto end of existing file //Linlyn u2 = new Linlyn("YOUR_SERVER", "USERNAME", "PASSWD"); //u2.append("pub", "score.txt", "append this info at ONCE", true); } catch(java.io.IOException ioe) {ioe.printStackTrace();} } } ////////////////////////////////////////// // split here for Linlyn.java // // At last! Java code to read/write files on the server from an applet! // This is the famous Linlyn code. // // Use: // compile this file, and have your applet call it as below. // // to upload a file: // Linlyn ftp = new Linlyn( , , ); // ftp.upload( , , ); // // to download a file: // Linlyn ftp = new Linlyn( , , ); // String contents = ftp.download( , ); // // the default is ASCII transfer, an overloaded method does bin. // // All parameters and return values are Strings. E.g. // Linlyn ftp = new Linlyn( "rtfm.mit.edu", "anonymous", "linden@" ); // String contents = ftp.download( // "/pub/usenet-by-group/comp.lang.java.programmer" // "Java_Programmers_FAQ" ); // // [the actual values above are not generally valid, substitute // your own server for your first attempt, see note 1.] // // Notes: // 1. Usual applet security rules apply: you can only get a file // from the server that served the applet. // 2. The applet server must also be an FTP server. This is NOT true // for some ISPs, such as best.com. They have separate FTP and // http machines. This code may work on such a setup if you put // the classfiles into the ftp area, and in the HTML file say: //