Solved

Open an html file from an application

Posted on 2006-11-20
32
194 Views
Last Modified: 2010-03-31
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
0
Comment
Question by:blarouche
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 14
  • 8
  • 6
  • +1
32 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 17979089
Try

Runtime.getRuntime().exec("cmd.exe /c start " + url);
0
 

Author Comment

by:blarouche
ID: 17979211
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/SwingTrader--bund--Wed_Nov_15_225311_EST_2006/Summary.html" );
                    }
            
                   } // end anonymous inner class
0
 
LVL 16

Expert Comment

by:Peter Kwan
ID: 17979291
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/SwingTrader--bund--Wed_Nov_15_225311_EST_2006/Summary.html" );
} catch (java.io.IOException e) { }
0
Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

 

Author Comment

by:blarouche
ID: 17979347
I did exactly that.
Now I can run the code but get nothing on screen
0
 

Author Comment

by:blarouche
ID: 17979386
The file loaded in my computer is not on my C drive:

E:/JAVA DISTRIBUTION/My CTA Platform/jars/reports/SwingTrader--bund--Wed_Nov_15_225311_EST_2006/Summary.html
0
 
LVL 16

Expert Comment

by:Peter Kwan
ID: 17979393
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")?
0
 
LVL 16

Expert Comment

by:Peter Kwan
ID: 17979434
Oops... You missed a space between start and url.
0
 

Author Comment

by:blarouche
ID: 17979446
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


0
 

Author Comment

by:blarouche
ID: 17979585
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 ??



0
 
LVL 16

Expert Comment

by:Peter Kwan
ID: 17979603
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/SwingTrader--bund--Wed_Nov_15_225311_EST_2006/Summary.html\"" );
0
 
LVL 16

Expert Comment

by:Peter Kwan
ID: 17979611
Oops... should be:

Runtime.getRuntime().exec("cmd.exe /c start " + "\"E:/JAVA DISTRIBUTION/My CTA Platform/jars/reports/SwingTrader--bund--Wed_Nov_15_225311_EST_2006/Summary.html\"" );
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 17979631
Try

Runtime.getRuntime().exec(new String[]{ "cmd.exe", "/c", "start", "E:/JAVA DISTRIBUTION/My CTA Platform/jars/reports/SwingTrader--bund--Wed_Nov_15_225311_EST_2006/Summary.html" });
0
 

Author Comment

by:blarouche
ID: 17979663
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>
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 17979680
Try making those forward slashes into double backslashes
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 17979684
(Only in the path of course)
0
 

Author Comment

by:blarouche
ID: 17979694

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/SwingTrader--bund--Wed_Nov_15_225311_EST_2006/Summary.html
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 17979733
Because only part of the command (starting the command intepreter [cmd.exe] ) has been fulfilled
0
 

Author Comment

by:blarouche
ID: 17979772
CEHJ

I tried double backslashes. Same result ...
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 17979781
Take pkwan's last and turn forward slashes in the path to doubled backslashes
0
 

Author Comment

by:blarouche
ID: 17979827



Here is what I did :

Runtime.getRuntime().exec("cmd.exe /c start " + "\"E:\\JAVA DISTRIBUTION\\My CTA Platform\\jars\\reports\\SwingTrader--bund--Wed_Nov_15_225311_EST_2006\\Summary.html\"" );


Same result....




0
 
LVL 16

Expert Comment

by:Peter Kwan
ID: 17979842
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\"" );
0
 

Author Comment

by:blarouche
ID: 17979943
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 ?

0
 

Author Comment

by:blarouche
ID: 17980316
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,FileProtocolHandler " +
                                            "E:/JAVA DISTRIBUTION/My CTA Platform/jars/reports/SwingTrader--bund--Wed_Nov_15_225311_EST_2006/Summary.html".toString());
0
 

Author Comment

by:blarouche
ID: 17980382

Now I would like the result to appear in a  TextArea. Is it possible ?



0
 
LVL 86

Expert Comment

by:CEHJ
ID: 17980413
You need to use  JEditorPane if you want the html to be interpreted
0
 

Author Comment

by:blarouche
ID: 17981029

Now that I Have this :

Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " +
                    pathreports+"SwingTrader--bund--Wed_Nov_15_225311_EST_2006/index.html".toString());
               }catch(IOException e){};


How do I put that into a JEditorPane ?
0
 
LVL 86

Accepted Solution

by:
CEHJ earned 125 total points
ID: 17981072
0
 

Author Comment

by:blarouche
ID: 17981363
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\\SwingTrader--bund--Wed_Nov_15_225311_EST_2006\\Summary.html\"" ";
                            JEditorPane editorPane = new JEditorPane(url);
                            editorPane.setEditable(false);
                       
                            JFrame frame = new JFrame();
                            frame.getContentPane().add(editorPane, BorderLayout.CENTER);
                            frame.setSize(200, 200);
                            frame.setVisible(true);
                        } catch (IOException e) {
                        }
0
 
LVL 92

Assisted Solution

by:objects
objects earned 125 total points
ID: 17983139
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
spring jars download 1 68
hashmap order 17 62
web project error add remove 1 83
import as existing maven project 3 77
An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Suggested Courses

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question