Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to run IE in java program 2

Status
Not open for further replies.

taken

Programmer
Jun 22, 2005
6
0
0
GB
HI,

I want to run IE in Java program, for example, click a button, then XML file will be displayed in IE. Can you tell me how to do? Thanks very much.

Best regards,

snow
 
Thanks for your reply, but in this example, com.apple.mrj.MRJFileUtils is need. How can I do?
I want to open XML file in IE in JAVA program, this file is stored at local machine.
Thanks again

snowhot
 
Here is an example that runs on my system and launches IE with the yahoo home page. YMMV.

import java.io.*;
public class Test {
public static void main (String args[]) throws IOException {
Runtime rt = Runtime.getRuntime();
rt.exec("c:\\progra~1\\plus!\\Micros~1\\Iexplore.exe }
}
 
It works! Thanks all very much. I am really very appreciate of you.

Good luck.
 
Hi SnowHot

But if the IE is installed in other path then what will happen???


Okay now for a better solution.

rt.exec("EXPLORER Helloworld.html");

Thanks
Shyam
 
Shyam,

This is really not a better solution. On my system 'EXPLORER' refers to windows explorer not Internet Explorer. If I try to use this, it doesn't open a browser, it generates an error, hence the solution I used above. This is why it's not portable. Does this actually work on your system? What OS are you using?
 
I think it should be:
Code:
Runtime rt = Runtime.getRuntime();
rt.exec("IEXPLORE Helloworld.html");
IEXPLORE lauches Explorer. The other method will not work on most people's machines. For example the path to my IE is at C:\PROGRAM FILES\INTERNET EXPLORER. IEXPLORE should be mapped to IE on all Windows Systems. Wushutwist
 
Wush,

Have you actually tried this? I have and it doesn't work. In fact, I have machines running windows 98, windows 2000 and windows nt and it doesn't work on any of them. The reason is because IExplore.exe is not in the system path (and there is no reason for it to be). That is why I used the complete path in my example above and why I said that this solution is NOT PORTABLE.

Please try running the examples that you give before you offer them as a solution. All of the things you say 'should' work, don't.

Regards,

Charles
 
Actually I did try it and it did work. As you said IExlore.exe may not be in your PATH. I was suggesting it as an alternative to your post because I know many machines do not store IE in the same directory and therefore you solution also would not work. The only real solution would be to check the windows registry for the directory path to IE and run that. Just to let you know I don't try to post blindly. Wushutwist
 
Hi Meandale

I work in windows 98 it is working fine for me.
If u use just Explorer, then it opens windows explorer.
If u specify a html file or any file with it, then it opens up with the IExplorer.

Shyam
 
I have to go with meadandale on this...

C:\>java Test
Exception in thread "main" java.io.IOException: CreateProcess: IEXPLORE error=2
at java.lang.Win32Process.create(Native Method)
at java.lang.Win32Process.<init>(Win32Process.java:66)
at java.lang.Runtime.execInternal(Native Method)
at java.lang.Runtime.exec(Runtime.java:551)
at java.lang.Runtime.exec(Runtime.java:418)
at java.lang.Runtime.exec(Runtime.java:361)
at java.lang.Runtime.exec(Runtime.java:325)
at Test.main(Test.java:7)

it does work with explorer though
 
This is why I stated above Your Mileage May Vary. I am running Windows 2000 and when I try to run it with explorer I get a windows explorer error.
 
Another alternative: Copy iexplore.exe to wherever you're running your program from.
 
Alternative No 2: Create a platform specific batch file and run it from your program.

Seth Juarez
Web Consultant
Holman's of Nevada
 
I think, EXPLORER opens an internet explorer if the url begins with &quot; So if you give the absolute URL you may not have a problem. I have tested this on w2k.
 
public void showDocument(String s) throws Exception
{
String s1 = &quot;rundll32 url.dll,FileProtocolHandler &quot; + s;
Process process = Runtime.getRuntime().exec(s1);
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top