URLContent.java
import java.net.URL;
import java.io.*;
/** 指定された URLのオブジェクトを得る URLContent */
public class URLContent {
/** 最初に呼び出されるメソッド */
public static void main( String argv[] ) {
if( argv.length != 1 ) {
System.err.println( "Usage: java URLContent urlname" );
System.exit(0);
}
try {
URL url = new URL( argv[0] );
Object content = url.getContent();
if( content instanceof BufferedInputStream ) {
BufferedReader br
= new BufferedReader( new InputStreamReader(
(InputStream)content ) );
String line;
while( ( line = br.readLine() ) != null )
System.out.println( line );
br.close();
}
}
catch( Exception e ){
System.err.println( e.getMessage() );
System.exit(-1);
}
}
}