How to get the result of executing an html file in your local hard disk from a java program?
I'm trying to get the result of executing an html file on my hard disk as a string (thats the type of whats displayed in running the file) form a java program for the first time and it seems i did not get it right.
here is the code:
import java.io.*;
import java.net.URL;
public class MapDir {
public static void main(String[] args) throws FileNotFoundException, IOException
{
String s = "file:///F:/Stuff/Muaz/Programming/Mobile Applications/J2ME/Ride Sharing System/RSS Server/routeDistance.html?addr1=30.065634,31.209473&addr2=29.984177,31.440052";
URL url = new URL("file", "Core", s);
BufferedReader r = new BufferedReader(new InputStreamReader(url.openStream()));
while((s = r.readLine()) != null)
{
System.out.println(s);
}
}
}
when I run the code I get the following error:
开发者_开发百科java.net.ConnectException: Connection refused: connect....
Of-course Im sure of the string File (s). I ran it form a browser and it works perfectly. The host name is also correct. So whats wrong? Please reply back as soon as you can. Thanks in advance.
Check the documentation for URL
, you are...
String s = "file://location";
URL url = new URL("file", "Core", s);
... initializing it incorrectly. Take a look at this link.
Cheers!
Edit: ok, this is a bit long for a comment.
First, the
URL
class has no method of executing an html file that I know of. Or any class, for that matter.Second, your code is READING the file, and it would work if it wasn't for the error we pointed out. How am I supposed to know that's not actually want you want to do? I thought the title was just bad english.
Third, nobody is paying us to answer your questions, so instead of barking, try thanking. The same attitude as in "answer as soon as you can" in your original post won't get you support or help.
Ah. I just had to say that. I'll accept any downvotes as just punishment.
Edit 2:
(From my comment below) @Muaz an HTML is just data. Nobody "runs" an HTML file, the same way you don't run a .doc, or a .avi -- you run another program that knows how to interpret this data and what to do with it. That program can be a web browser, Microsoft Word, or the VLC media player; but whatever the case, it's not the data file the one that's being executed. –
精彩评论