DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   Java (http://www.daniweb.com/forums/forum9.html)
-   -   open unknown file types through java (http://www.daniweb.com/forums/thread139035.html)

linu Aug 7th, 2008 9:58 am
open unknown file types through java
 
Hello
Please help me with the following: i am trying to open a file with a specific application using java. I am working on a desktop application.
The following code using java.awt.Desktop works for known extension types,but when trying to open a file with an unknown extension it throws an exception. I know this is about to happen, because it's in the class documentation, but what i want to ask you is if there is another way of popping up the windows "open with" dialog through java. I just don't want to let unknown extension file types untreated. This is the code i use, and it works,just that it throws an exception for unknown file types:

import java.awt.Desktop
...
if (Desktop.isDesktopSupported()) {
        desktop = Desktop.getDesktop();
        temp = new File(localPath);
        desktop.open(temp);
}

Thank you very much

sanzilla Aug 9th, 2008 7:22 am
Re: open unknown file types through java
 
use the JFileChooser , but that is swing ,

just google and find something about JFileChooser example
http://java.sun.com/docs/books/tutor...lechooser.html

will help you ,

linu Aug 9th, 2008 4:06 pm
Re: open unknown file types through java
 
thx,the problem was solved using

String str = "RUNDLL32.EXE SHELL32.DLL,OpenAs_RunDLL";
r = Runtime.getRuntime();
Process p = r.exec(str + "C:\\test.txt");


All times are GMT -4. The time now is 10:36 am.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC