📄 testurlconnection.java
字号:
import java.net.*;
import java.io.*;
public class TestURLConnection
{
public static void main(String args[])
{
String s ;
try
{
URL MyURL = new URL("http://ym/cgi/java?answer.class");
URLConnection MyURLConnection = MyURL.openConnection();
PrintStream ps = new PrintStream(MyURLConnection.getOutputStream());
BufferedReader dis = new BufferedReader(
new InputStreamReader(MyURLConnection.getInputStream()));
ps.println("Hello! This is a test.");
ps.close();
while( (s = dis.readLine()) != null )
{
System.out.println(s);
}
dis.close();
}
catch(MalformedURLException e)
{ System.out.println("URL in wrong form, check it again.");
}
catch(IOException e)
{ System.out.println("IO Exception ocurred when get information.");
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -