readserverfile.java.bak

来自「nanjing university cs 的java课件。 对新手很有用。付」· BAK 代码 · 共 47 行

BAK
47
字号
import java.net.*;
import java.io.*;
import java.awt.*;
import java.awt.event.*;

public class ReadServerFile extends Frame {
	TextArea contents = new TextArea("HTML content");
	Button readButton = new Button("read");
	URL fileURL;
	InputStream input;
	String text = "";
	DataInputStream dataInput;
	public ReadServerFile(){
		this.add(contents);
		this.add(readButton, BorderLayout.SOUTH);
		this.addWindowListener(new WindowAdapter(){
			public void windowClosing(WindowEvent e){
				System.exit(0);
			}
		});
		readButton.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e) {
				read();
			}
		});
		this.setSize(400,300);
		this.setVisible(true);
	}
	
	void read(){
		try{
			fileURL = new URL("http://cs.nju.edu.cn/cs2/jiaowang/ibmtech/zc.html");
			input = fileURL.openStream();
			dataInput=new DataInputStream(input);
	        contents.setText("The file contents are:\n");
	        while ((text=dataInput.readLine())!=null)
	        	contents.appendText(text+"\n");
	        dataInput.close();   
		}
		catch(Exception e){
		}
	}
	
	public static void main(String[] args) throws Exception {
		     new ReadServerFile();
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?