Click here to Skip to main content
15,887,302 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello everyone,

I need to help about openning a html file under a Jbutton. I created a button on the panel and named it as tables. And I created a html file named as tables in the project folder. The program is expected to do this;

When the user clicked on the butto, the html file should be opened on the browser.
HTML file is static no need a database or any other things. You may think there is no relation with the java project. The user just should see it on the browser.
I searched too much. However, I couldn't solve this.

Java
  private void btnDevelopersActionPerformed(java.awt.event.ActionEvent evt) {                                              

try{ 
//OPEN A HTML FILE ON MY COMPUTER

} 
catch(Exception ex){ 
System.out.println("cannot execute command. " +ex); 
} 

    }  
Posted

even simpler:

Java
// find program for given file
Program p = Program.findProgram("pdf"); // could also be html or whatever 
p.execute(printFilePath); // throw file at program


One simply lets the OS decide and take action. It's pretty failsafe.
 
Share this answer
 
Comments
FoxRoot 22-Nov-12 7:08am    
Thanks :) Torsent I am very far away your skills, talends, experiences. I am just beginner :) Thank you for all.
Hi,

Have a look at this similar discussion:
http://stackoverflow.com/questions/4649816/open-local-html-page-java[^]
 
Share this answer
 
Comments
FoxRoot 21-Oct-12 11:11am    
My website is not dynamic. I just want to open an html file and I am using netbeans.
Thomas Daniels 21-Oct-12 11:13am    
What do you mean with 'open'.
Do you mean read the file?
FoxRoot 21-Oct-12 11:21am    
No. When the user clicked on the button, the html file should be seen on the browser. When I cliked on the html file it is opened on the browser. I want this.
Thomas Daniels 21-Oct-12 11:24am    
So, I've posted a link to a similar discussion.
I think the first answer is what you need.
FoxRoot 21-Oct-12 11:34am    
Yes I know the answer but I couldn't understand the link that you posted.
Java
String webpage="C:\\myRootFolder\\myWebPage.html";
Runtime.getRuntime().exec("cmd /c start "+webpage);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900