connectiontest.java

来自「the program connects to an URL and retri」· Java 代码 · 共 43 行

JAVA
43
字号
/*
the program connects to the "http://mercur.utcluj.ro/lab/index.php" URL and retrieves the
index.php file content
*/


import java.net.*;
import java.io.*;

class ConnectionTest {
    public static void main(String args[]) {
        try {
            URL remote_url = new URL("http://mercur.utcluj.ro/lab/index.php");
            URLConnection remote_connection = remote_url.openConnection();
            BufferedReader dis;
	    String inputLine;
	    String server_text = new String();


	    dis = new BufferedReader(new InputStreamReader(remote_connection.getInputStream()));
            while ((inputLine = dis.readLine()) != null) {
                //System.out.println(inputLine);
		server_text += inputLine;
            }
	    dis.close();

		FileOutputStream fisIesire=new FileOutputStream("E://temp.txt");
			
		DataOutputStream dos = new DataOutputStream (fisIesire);
		dos.writeUTF(server_text);
		dos.close();



        } catch (MalformedURLException me) {
            System.out.println("MalformedURLException: " + me);
        } catch (IOException ioe) {
            System.out.println("IOException: " + ioe);
        }
    }
}

⌨️ 快捷键说明

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