50,530
社区成员
发帖
与我相关
我的任务
分享
import java.io.*;
import java.net.*;
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(null != (s = dis.readLine())){
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");
}
}
}