package
com.test;
import java.net. * ;
import java.io. * ;
public class urltest {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
String info = "" ;
String url = " http://localhost/test.html " ;
info = getUrlFileContent(url);
System.out.println(info);
}
public static String getUrlFileContent(String strurl) {
URL url;
URLConnection urlc;
String txt = new String();
InputStream is;
int i;
try {
url = new URL(strurl);
urlc = url.openConnection();
urlc.connect();
is = urlc.getInputStream();
i = is.read();
while (i != - 1 ) {
txt = txt + ( char ) i;
i = is.read();
}
is.close();
} catch (MalformedURLException mfe) {
System.out.println( " URL form error! " );
} catch (IOException ioe) {
System.out.println( " IO Exception! " );
}
return txt;
}
}
import java.net. * ;
import java.io. * ;
public class urltest {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
String info = "" ;
String url = " http://localhost/test.html " ;
info = getUrlFileContent(url);
System.out.println(info);
}
public static String getUrlFileContent(String strurl) {
URL url;
URLConnection urlc;
String txt = new String();
InputStream is;
int i;
try {
url = new URL(strurl);
urlc = url.openConnection();
urlc.connect();
is = urlc.getInputStream();
i = is.read();
while (i != - 1 ) {
txt = txt + ( char ) i;
i = is.read();
}
is.close();
} catch (MalformedURLException mfe) {
System.out.println( " URL form error! " );
} catch (IOException ioe) {
System.out.println( " IO Exception! " );
}
return txt;
}
}