Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Vamsee Bandaru
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13064
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20550
57
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic