File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes I/O and Streams and the fly likes Using the openConnect() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "Using the openConnect()" Watch "Using the openConnect()" New topic

Using the openConnect()

von rodrig

Joined: Jun 28, 2002
Posts: 2
I am trying to use the openConnect() to see if an url exist and plus check to see if there are any error code. My problem is with the check the error code I tried using the getResponseCode and got error message method getResponseCode() not found in class Can someone help me figure out how to use this? I attached my code:

import java.lang.Object.*;

public class URLConnTest2 {

public static void main (String args[]) {
try {
//Url to try to connect to
URL u1 = new URL("");
try {
//get a handle to the URLConnection object for this url
URLConnection uc = openConnection();
System.out.println("Error message " + uc.getRequestCode());
//Check whether this URL object can be "read"
if (uc.getDoInput() == true) {
//Attach an input Stream and read from this input stream
InputStream iStream = InputStream();
DataInputStream data = new iStream);
System.out.println("URL is valid");
data.close(); //close the input stream

} catch (IOException ie) {
System.out.println("URL is NOT valid.");
// retCode = false;
}catch (MalformedURLException e) {
System.out.println("Caught MUE !");
// retCode = false;
// return retCode;
Kevin Li

Joined: Sep 25, 2001
Posts: 21
Here is a example for open url and read stream.
public static String readURL(String urlstr){
StringBuffer sb = new StringBuffer();
URL url = new URL(urlstr);
BufferedReader in = new BufferedReader(
new InputStreamReader(
int tmp = -1;
char temp = ' ';
temp = (char)tmp;
sb = sb.append(temp);
}catch(IOException ioe){
}catch(Exception e){
return sb.toString();
jason adam
Chicken Farmer ()
Ranch Hand

Joined: May 08, 2001
Posts: 1932
Please review the JavaRanch Naming Policy then edit your profile so that your publicly displayed name complies with the rules.
Thanks for your cooperation.
I agree. Here's the link:
subject: Using the openConnect()
It's not a secret anymore!