permaculture playing cards*
The moose likes Java in General and the fly likes Could not able to open the file in the local system using http protocol Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Could not able to open the file in the local system using http protocol" Watch "Could not able to open the file in the local system using http protocol" New topic
Author

Could not able to open the file in the local system using http protocol

Vamsee Bandaru
Greenhorn

Joined: Jun 07, 2008
Posts: 1
hi Ranchers
I want to open the file in my system using http protocol. I wrote the following lines of code.

I have shared the PoeticLogs folder.
Server: Tomcat 6.0

String urlString = "http://H_VAMSEE/PoeticLogs/ServerLog_2008-06-07.log";

try {
URL url = new URL(urlString);
url.openStream();
fileExists = true;
} catch (MalformedURLException mue) {
mue.printStackTrace();
// Do nothing. fileExist will be false and error will display.
} catch (IOException ioe) {
// Do nothing. fileExist will be false and error will display.
}

After url.openStream(); it is breaking out of the code with the following exception.
Connection refused: connect

Can any one please help out in this.

Thanks,
Vamsee
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12803
    
    5
I was under the impression that the correct protocol was "file:///" not "http://" - as in


When the URL starts with "http://H_VAMSEE/", java is going to try to find a http server named H_VAMSEE, not a file.

Bill
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19718
    
  20

You're right William. Unless your PC was called H_VAMSEE and had a web server like IIS or Apache installed and active, and therein there was the PoeticLogs/ServerLog_2008-06-07.log file, this code would fail.

Now Vamsee, you said you have shared the PoeticLogs folder, and are using Tomcat. That make me think that you have installed a web server indeed, and I'm assuming then that your PC is called H_VAMSEE indeed. That would make the URL valid - but only if your web server is also using port 80. If not, and I think this is the case, you should specify the port as well:
http://H_VAMSEE:8080/PoeticLogs/ServerLog_2008-06-07.log

Of course your port could be different, but this is the default for Tomcat.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Could not able to open the file in the local system using http protocol