import java.awt.*;
import java.io.*;
import java.net.*;/**
* <strong>ReadFromURLAppletExample</strong> -- reading the file
* specified by a URL.
*/
public class ReadFromURLAppletExample extends java.applet.Applet { TextArea messageLog = new TextArea(4, 40);
/** Builds the applet's interface. */
public void init() {
setLayout(new BorderLayout());
add("Center", messageLog);
} /**
* Called when the applet is started or when the browser
* returns to the applet's page.
*/
public void start() { URL url = getDocumentBase();
URLConnection connection;
String inputLine;
DataInputStream inStream; /* Create the URL connection and get its input stream.
* Wrap a DataInputStream around the input stream in order to
* read from it one line at a time.
* Print out only lines that contain the specified string.
* Close the input stream when done.
*/
try {
connection = url.openConnection();
messageLog.appendText("File read from URL " + url + ":\n");
inStream = new DataInputStream (connection.getInputStream());
while (null != (inputLine = inStream.readLine())) {
messageLog.appendText(inputLine + "\n");
}
inStream.close();
} catch (IOException e) {
System.err.println("Exception: " + e);
}
} /** Handles action events. */
public boolean action(Event evt, Object what) {
return super.action(evt, what);
} /** Draws the applet. */
public void paint(Graphics g) {
}}This one???
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货