blarouche
asked on
Open an html file from an application
Hi Experts,
I have an application and a menu called Reports. From that menu I have to open an HTML file with a browser.
Actually I have a menu open that can open files but I can't open HTML files.
Can you help me with that.
Thank you
I have an application and a menu called Reports. From that menu I have to open an HTML file with a browser.
Actually I have a menu open that can open files but I can't open HTML files.
Can you help me with that.
Thank you
ASKER
Here is my code
I've got the following error : Unhandled exception type IOException
class MyHTMLListener extends AbstractAction{
//display message dialog when user selects About ...
public void actionPerformed( ActionEvent event )
{
Runtime.getRuntime().exec( "cmd.exe /c start" + "E:/JAVA DISTRIBUTION/My CTA Platform/jars/reports/Swin gTrader--b und--Wed_N ov_15_2253 11_EST_200 6/Summary. html" );
}
} // end anonymous inner class
I've got the following error : Unhandled exception type IOException
class MyHTMLListener extends AbstractAction{
//display message dialog when user selects About ...
public void actionPerformed( ActionEvent event )
{
Runtime.getRuntime().exec(
}
} // end anonymous inner class
You need to catch the IOException by surrounding the Runtime.getRuntime.exec() call with try-catch, like this:
try {
Runtime.getRuntime().exec( "cmd.exe /c start" + "E:/JAVA DISTRIBUTION/My CTA Platform/jars/reports/Swin gTrader--b und--Wed_N ov_15_2253 11_EST_200 6/Summary. html" );
} catch (java.io.IOException e) { }
try {
Runtime.getRuntime().exec(
} catch (java.io.IOException e) { }
ASKER
I did exactly that.
Now I can run the code but get nothing on screen
Now I can run the code but get nothing on screen
ASKER
The file loaded in my computer is not on my C drive:
E:/JAVA DISTRIBUTION/My CTA Platform/jars/reports/Swin gTrader--b und--Wed_N ov_15_2253 11_EST_200 6/Summary. html
E:/JAVA DISTRIBUTION/My CTA Platform/jars/reports/Swin
Can you please type "e.printStackTrace();" in your catch block and re-run it? See if there is any exception thrown.
Also, can you run it by typing the command in "Run" dialog ("Start->Run")?
Also, can you run it by typing the command in "Run" dialog ("Start->Run")?
Oops... You missed a space between start and url.
ASKER
Ok
I have included the e.printStackTrace() in my catch block and rerun. No error message appears in my console.
I have open the file with the Run dialog and it worked without problem
I have included the e.printStackTrace() in my catch block and rerun. No error message appears in my console.
I have open the file with the Run dialog and it worked without problem
ASKER
Yes you're right it helped but I still can't get my HTML file....
I have a error message from Windows stating that it can't find E:/JAVA
I thing that the problem comes with the separated bars /. If I can this / with \ Java is not accepting it ??
I have a error message from Windows stating that it can't find E:/JAVA
I thing that the problem comes with the separated bars /. If I can this / with \ Java is not accepting it ??
I don't think so. You need to quote the url with double-quotes, as the following:
Runtime.getRuntime().exec( "cmd.exe /c start" + "\"E:/JAVA DISTRIBUTION/My CTA Platform/jars/reports/Swin gTrader--b und--Wed_N ov_15_2253 11_EST_200 6/Summary. html\"" );
Runtime.getRuntime().exec(
Oops... should be:
Runtime.getRuntime().exec( "cmd.exe /c start " + "\"E:/JAVA DISTRIBUTION/My CTA Platform/jars/reports/Swin gTrader--b und--Wed_N ov_15_2253 11_EST_200 6/Summary. html\"" );
Runtime.getRuntime().exec(
Try
Runtime.getRuntime().exec( new String[]{ "cmd.exe", "/c", "start", "E:/JAVA DISTRIBUTION/My CTA Platform/jars/reports/Swin gTrader--b und--Wed_N ov_15_2253 11_EST_200 6/Summary. html" });
Runtime.getRuntime().exec(
ASKER
We are making progress...
Now what I get is a command window from DOS with this message :
Microsoft Windows XP [version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.
E:\JAVA DISTRIBUTION\My CTA Platform\src\SteadFast>
Now what I get is a command window from DOS with this message :
Microsoft Windows XP [version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.
E:\JAVA DISTRIBUTION\My CTA Platform\src\SteadFast>
Try making those forward slashes into double backslashes
(Only in the path of course)
ASKER
I don't know why I get this message E:\JAVA DISTRIBUTION\My CTA Platform\src\SteadFast>
since I have included this directory in my code E:/JAVA DISTRIBUTION/My CTA Platform/jars/reports/Swin
Because only part of the command (starting the command intepreter [cmd.exe] ) has been fulfilled
ASKER
CEHJ
I tried double backslashes. Same result ...
I tried double backslashes. Same result ...
Take pkwan's last and turn forward slashes in the path to doubled backslashes
ASKER
Here is what I did :
Runtime.getRuntime().exec(
Same result....
Can you please try to copy your summary.html and put it under E:
and run as:
Runtime.getRuntime().exec( "cmd.exe /c start " + "\"E:\\Summary.html\"" );
and run as:
Runtime.getRuntime().exec(
ASKER
I tried it same result. I get a DOS console with the same message.
Guys maybe I forgot to mention a very important thing. All my Java distribution is install on E drive.
I don't know if it matters ?
Guys maybe I forgot to mention a very important thing. All my Java distribution is install on E drive.
I don't know if it matters ?
ASKER
Guys I found it researching on the net.
I am not programming since a long time so I don't know why it works but it works !!!
Here is the code I used :
Runtime.getRuntime().exec( "rundll32 url.dll,FileProtocolHandle r " +
"E:/JAVA DISTRIBUTION/My CTA Platform/jars/reports/Swin gTrader--b und--Wed_N ov_15_2253 11_EST_200 6/Summary. html".toSt ring());
I am not programming since a long time so I don't know why it works but it works !!!
Here is the code I used :
Runtime.getRuntime().exec(
"E:/JAVA DISTRIBUTION/My CTA Platform/jars/reports/Swin
ASKER
Now I would like the result to appear in a TextArea. Is it possible ?
You need to use JEditorPane if you want the html to be interpreted
ASKER
Now that I Have this :
Runtime.getRuntime().exec(
pathreports+"SwingTrader--
}catch(IOException e){};
How do I put that into a JEditorPane ?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
When I do this I have the same problem as before nothing's happens
try {
String url = "\"E:\\JAVA DISTRIBUTION\\My CTA Platform\\jars\\reports\\S wingTrader --bund--We d_Nov_15_2 25311_EST_ 2006\\Summ ary.html\" " ";
JEditorPane editorPane = new JEditorPane(url);
editorPane.setEditable(fal se);
JFrame frame = new JFrame();
frame.getContentPane().add (editorPan e, BorderLayout.CENTER);
frame.setSize(200, 200);
frame.setVisible(true);
} catch (IOException e) {
}
try {
String url = "\"E:\\JAVA DISTRIBUTION\\My CTA Platform\\jars\\reports\\S
JEditorPane editorPane = new JEditorPane(url);
editorPane.setEditable(fal
JFrame frame = new JFrame();
frame.getContentPane().add
frame.setSize(200, 200);
frame.setVisible(true);
} catch (IOException e) {
}
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Runtime.getRuntime().exec(