📄 urlconnectionreader.java.bak
字号:
import java.net.*;
import java.io.*;
import java.awt.*;
import java.awt.event.*;
public class URLConnectionReader extends Frame {
TextArea contents = new TextArea("HTML content");
Button readButton = new Button("read");
URL fileURL;
String text = "";
public URLConnectionReader(){
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://localhost:8080/test.html");
URLConnection tc = fileURL.openConnection();
BufferedReader in = new BufferedReader(
new InputStreamReader(tc.getInputStream()));
contents.setText("The file contents are:\n");
while ((text=in.readLine())!=null)
contents.appendText(text+"\n");
in.close();
}
catch(Exception e){
}
}
public static void main(String[] args) throws Exception {
new URLConnectionReader();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -