urlrw.java

来自「有关java的源程序,为讲授java程序设计课程使用」· Java 代码 · 共 35 行

JAVA
35
字号
import java.io.*;
import java.net.*;
public class URLRW
{
	public static void main(String args[])
	{ 
		String stringText="Input Output Text";
		try
		{
//向CGI程序发送数据
	URL url=new URL("http://192.9.200.29/");
	URLConnection uc=url.openConnection();
	uc.connect();
/*
    uc.setDoOutput(true);
	PrintStream ps=new PrintStream(uc.getOutputStream());
	ps.println("string="+stringText);
	ps.close();
*/
//取得CGI所返回的数据
    
	DataInputStream dis=new DataInputStream(uc.getInputStream());
	String getText;
	while((getText=dis.readLine())!=null)
		System.out.println(getText);
	dis.close();
		}
		catch(MalformedURLException e)
		{ System.err.println("MalformedUrlException:"+e);
		}
		catch(IOException e)
		{ System.err.println("IOException"+e);
		}
	}
}

⌨️ 快捷键说明

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