| Forums.Sureshkumar.net : A Perfect Place to Share Knowledge Blogs Games Magazines |
|
|
#1 (permalink) |
|
Member
Join Date: Feb 2006
Location: India
Posts: 45
Thanks: 0 Thanked 2 Times in 2 Posts Thanks: 0
Thanked 2 Times in 2 Posts
Rep Power: 3
|
Opening Help(.chm) Files from java
hi
How to open .chm files from java application. For examples If i want to open calc help file i have used this java.lang.Runtime.getRuntime().exec("rundll32"+" "+"url.dll,FileProtocolHandler"+" "+"calc.chm"); This is working only when i am giving the absolute path of the help file but i dont want to hard code the path so how to open .chm file when help file name is given Thanks Lakshmi |
|
|
|
|
|
#2 (permalink) |
|
Moderator
Join Date: Apr 2006
Location: India
Posts: 636
Thanks: 57 Thanked 77 Times in 62 Posts Thanks: 57
Thanked 77 Times in 62 Posts
Rep Power: 17
|
Re: Help Files
Hi lakshmi,
let us assume u have a textbox which accepts the chm filename, when u click on submit or a button, pass the name of the text box to the method in the class as a parameter which is having the given code. you can use a JFileChooser to select the file (like open dialog box) fileChooser = new JFileChooser(); fileChooser.setCurrentDirectory( new File(System.getProperty("user.dir"))); fileChooser.setFileSelectionMode( JFileChooser.FILES_AND_DIRECTORIES); fileChooser.setMultiSelectionEnabled(false); you can get the absolute path from this fileChooser, pls browse thru the JFileChooser API and try to get the absolute path of a file which would help u, then perform the other operations class openChm() { public void openChmMethod(String chmFileName) { java.lang.Runtime.getRuntime().exec("rundll32"+" "+"url.dll,FileProtocolHandler"+" "+chmFileName); } } In the calling function if it is an AWT Application String fileName = textField.getText(); if(ae.getSource()=="openchm") { openChm oc = new openChm(); oc.openChmMethod(fileName); } Anyway u would be entering the help file name, i think this should help u, pls let me know your questions Thank You
__________________
M0h@n Last edited by t_mohan; 15-11-06 at 07:03 PM. |
|
|
|
| The Following User Says Thank You to t_mohan For This Useful Post: |
sk_kireeti (23-11-06)
|
|
|
#3 (permalink) | |
|
Member
Join Date: Oct 2006
Posts: 66
Thanks: 2 Thanked 1 Times in 1 Posts Thanks: 2
Thanked 1 Time in 1 Post
Rep Power: 3
|
Re: Help Files
Hi Mohan can u plz give me the code how to open a notepad file from a java progrmme............
Quote:
|
|
|
|
|
|
|
#4 (permalink) |
|
Moderator
Join Date: Apr 2006
Location: India
Posts: 636
Thanks: 57 Thanked 77 Times in 62 Posts Thanks: 57
Thanked 77 Times in 62 Posts
Rep Power: 17
|
Re: Help Files
Hi Hari,
Please find the code below for opening an Notepad file, pls refer the API for java.lang.Runtime and let me know your questions import java.lang.Runtime; public class openNotePad { public static void main(String args[]) { try{ Runtime r = Runtime.getRuntime(); r.exec("notepad.exe"); }catch(Exception e) { System.out.println("Exception:"+e); e.printStackTrace(); } } } If you want to open a file by default while opening the notepad editor , please add the line as given below, Since \ is an escape sequence in Java we have to give two slashes to recognize the path r.exec("notepad.exe c:\\someEx.java"); If the file is already existing it gets opened , or the notepad editor will ask you a confirmation to create the file or not. Please let me know your questions Thank You
__________________
M0h@n Last edited by t_mohan; 23-11-06 at 01:53 PM. |
|
|
|
| The Following User Says Thank You to t_mohan For This Useful Post: |
harikotha (23-11-06)
|
|
|
#5 (permalink) |
|
Super Moderator
Join Date: Feb 2006
Location: Hyderabad
Posts: 2,355
Thanks: 117 Thanked 240 Times in 197 Posts Thanks: 117
Thanked 240 Times in 197 Posts
Blog Entries: 4
Rep Power: 51
|
Re: Help Files
Another way to open any kind of file is to take help of explorer.exe command. Using this, you can open any windows registered programs. i.e., if you are able to open a file by double click (may be single click in some cases) then you can open it with IE also.
Following is the modified version of Mohan's program to accomadate this import java.lang.Runtime; public class openNotePad { public static void main(String args[]) { try{ Runtime r = Runtime.getRuntime(); r.exec("explorer "+ physical_file_path); //it doesn't care what kind of file it is, until it is of registered file type. }catch(Exception e) { System.out.println("Exception:"+e); e.printStackTrace(); } } } |
|
|
|
| The Following User Says Thank You to sk_kireeti For This Useful Post: |
harikotha (23-11-06)
|
|
|
#6 (permalink) | |
|
Member
Join Date: Oct 2006
Posts: 66
Thanks: 2 Thanked 1 Times in 1 Posts Thanks: 2
Thanked 1 Time in 1 Post
Rep Power: 3
|
Re: Help Files
Hi Mohan ,
Its working thanks for ur replay.and no quiries for me ......... Quote:
|
|
|
|
|
|
|
#7 (permalink) | |
|
Member
Join Date: Oct 2006
Posts: 66
Thanks: 2 Thanked 1 Times in 1 Posts Thanks: 2
Thanked 1 Time in 1 Post
Rep Power: 3
|
Re: Help Files
Hi Kireeti ,
Thanks for the modified version,but what can i give the physical_file_path,i gave the path like this f:\\hari.java but its giving some errors......... let me know clearly with an example of chm file plz , Quote:
|
|
|
|
|
|
|
#8 (permalink) |
|
Super Moderator
Join Date: Feb 2006
Location: Hyderabad
Posts: 2,355
Thanks: 117 Thanked 240 Times in 197 Posts Thanks: 117
Thanked 240 Times in 197 Posts
Blog Entries: 4
Rep Power: 51
|
Re: Opening Help(.chm) Files from java
Harikotha,
Here is the exact copy of what I have done in my system... import java.lang.Runtime; public class showanyfile { public static void main(String args[]) { try{ Runtime r = Runtime.getRuntime(); r.exec("explorer " + "E:\\Kireeti\\Books\\Testing Concepts\\1.chm" ); //r.exec("explorer " + "E:\\Kireeti\\Books\\ProC.pdf" ); //it doesn't care what kind of file it is, until it is of registered file type. }catch(Exception e) { System.out.println("Exception:"+e); e.printStackTrace(); } } } Even though I have commented out one line, it is also working. Hope it helps. Thanks, Krishna |
|
|
|
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Practice Question in JAVA | sowmya571 | JAVA Technologies | 8 | 15-02-08 08:09 PM |
| JAVA Downloads | yathish | JAVA Technologies | 2 | 22-01-07 01:37 PM |
| Opening for Core Java, C++ Developers!!! | sridhar | EXPERIENCED JOBS | 0 | 06-11-06 10:14 PM |
| Sun Certification for Java | alchemist | JAVA Technologies | 8 | 26-09-06 12:58 PM |
| java notes | naga | JAVA Technologies | 5 | 22-09-06 10:30 PM |