Forums.Sureshkumar.net : A Perfect Place to Share Knowledge         Blogs     Games    Magazines    

"Sharing knowledge does not lessen your store, often it gets you more. Sharing plays a key role in relationships and bonding, happens in small steps and is assisted through community membership."

Go Back   SURESHKUMAR.NET FORUMS > TECHNICAL DISCUSSIONS > JAVA Technologies
Register FAQ Members List Calendar Games Blogs Search Today's Posts Mark Forums Read

   

Reply
 
LinkBack Thread Tools Rate Thread Display Modes
Old 14-11-06, 04:07 PM   #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 solletilakshmi has disabled reputation
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
solletilakshmi is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 15-11-06, 06:51 PM   #2 (permalink)
Moderator
 
t_mohan's Avatar
 
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 t_mohan is a splendid one to behold t_mohan is a splendid one to behold t_mohan is a splendid one to behold t_mohan is a splendid one to behold t_mohan is a splendid one to behold t_mohan is a splendid one to behold t_mohan is a splendid one to behold
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.
t_mohan is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
The Following User Says Thank You to t_mohan For This Useful Post:
sk_kireeti (23-11-06)
Old 23-11-06, 12:13 AM   #3 (permalink)
Member
 
harikotha's Avatar
 
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 harikotha will become famous soon enough
Re: Help Files

Hi Mohan can u plz give me the code how to open a notepad file from a java progrmme............















Quote:
Originally Posted by t_mohan View Post
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
harikotha is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 23-11-06, 01:49 PM   #4 (permalink)
Moderator
 
t_mohan's Avatar
 
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 t_mohan is a splendid one to behold t_mohan is a splendid one to behold t_mohan is a splendid one to behold t_mohan is a splendid one to behold t_mohan is a splendid one to behold t_mohan is a splendid one to behold t_mohan is a splendid one to behold
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.
t_mohan is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
The Following User Says Thank You to t_mohan For This Useful Post:
harikotha (23-11-06)
Old 23-11-06, 03:16 PM   #5 (permalink)
Super Moderator
 
sk_kireeti's Avatar
 
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 sk_kireeti has a reputation beyond repute sk_kireeti has a reputation beyond repute sk_kireeti has a reputation beyond repute sk_kireeti has a reputation beyond repute sk_kireeti has a reputation beyond repute sk_kireeti has a reputation beyond repute sk_kireeti has a reputation beyond repute sk_kireeti has a reputation beyond repute sk_kireeti has a reputation beyond repute sk_kireeti has a reputation beyond repute sk_kireeti has a reputation beyond repute
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();
}

}
}
sk_kireeti is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
The Following User Says Thank You to sk_kireeti For This Useful Post:
harikotha (23-11-06)
Old 23-11-06, 08:08 PM   #6 (permalink)
Member
 
harikotha's Avatar
 
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 harikotha will become famous soon enough
Re: Help Files

Hi Mohan ,
Its working thanks for ur replay.and no quiries for me .........





Quote:
Originally Posted by t_mohan View Post
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
harikotha is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 23-11-06, 08:16 PM   #7 (permalink)
Member
 
harikotha's Avatar
 
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 harikotha will become famous soon enough
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:
Originally Posted by sk_kireeti View Post
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();
}

}
}
harikotha is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 23-11-06, 08:41 PM   #8 (permalink)
Super Moderator
 
sk_kireeti's Avatar
 
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 sk_kireeti has a reputation beyond repute sk_kireeti has a reputation beyond repute sk_kireeti has a reputation beyond repute sk_kireeti has a reputation beyond repute sk_kireeti has a reputation beyond repute sk_kireeti has a reputation beyond repute sk_kireeti has a reputation beyond repute sk_kireeti has a reputation beyond repute sk_kireeti has a reputation beyond repute sk_kireeti has a reputation beyond repute sk_kireeti has a reputation beyond repute
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
sk_kireeti is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On
Trackbacks are On
Pingbacks are On
Refbacks are On

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


All times are GMT +6.5. The time now is 05:32 PM.





Search Engine Optimization by vBSEO 3.1.0