⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 readserverme.java

📁 Java1.5下获得网页的Html文档的源程
💻 JAVA
字号:
//import java.applet.*;
import java.awt.*;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import java.net.*;
import java.io.*;

public class ReadServerMe extends Frame{
	private TextArea contents;
	private String site;
	
	public ReadServerMe(String s)
	{
		contents = new TextArea("Please wait ...", 100,140);
		add (contents);
		site = new String(s);
	}
	
	public void run()
	{
		URL fileURL = null;
		InputStream input;
		BufferedReader  dataInput;
		String text;
		FileOutputStream fout;//
		try{
			fileURL = new URL(site);//"http://www.bupt.edu.cn");//"http://www.deitel.com/test/test.txt");
		}
		catch (MalformedURLException e){
			System.err.println("Exception: " + e.toString());
		}
		
		try{
			input = fileURL.openStream();
			dataInput = new BufferedReader (new InputStreamReader(input));
			contents.setText("The file contents are:\n");
			fout = new FileOutputStream("fout.txt");//
			while((text = dataInput.readLine()) != null){
				text += "\n";
				contents.append(text);
				//char buf[] = new char[text.length()];
				//text.getChars(0, text.length(), buf, 0);
				byte buf[] = text.getBytes();
				for(int i = 0; i < buf.length; i++)
					fout.write(buf[i]);
			}
			
			fout.close();
			dataInput.close();
		}
		catch(IOException e){
			System.err.println("Exception: " + e.toString());
		}
		catch(Exception e){
			System.err.println("Exception: " + e.toString());
		}
		
	}
	
	public static void main(String args[])
	{
		ReadServerMe r = new ReadServerMe("http://www.bupt.edu.cn");
		r.run();
		r.setSize(600,400);
		r.setVisible(true);
		//r.addWindowListener(new QuitWindow(this));
		r.addWindowListener(new WindowListener(){
			public void windowClosing(WindowEvent e){ 
			    System.exit(0);  
			}  
			public void windowOpened(WindowEvent e){};  
			public void windowClosed(WindowEvent e){};  
			public void windowIconified(WindowEvent e){}; 
			public void windowDeiconified(WindowEvent e){}; 
			public void windowActivated(WindowEvent e){};  
			public void windowDeactivated(WindowEvent e){};
		}); 

	}
}
/*
class QuitWindow implements WindowListener 
{  
	private ReadServerMe rsm;
	
	public QuitWindow(ReadServerMe rsm)
	{
		this.rsm = rsm;
	}
	public void windowClosing(WindowEvent e){ 
		rsm.dispose();
	    //System.exit(0);  
	}  
	public void windowOpened(WindowEvent e){};  
	public void windowClosed(WindowEvent e){};  
	public void windowIconified(WindowEvent e){}; 
	public void windowDeiconified(WindowEvent e){}; 
	public void windowActivated(WindowEvent e){};  
	public void windowDeactivated(WindowEvent e){}; 
}*/

⌨️ 快捷键说明

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