File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes Opening a file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Opening a file" Watch "Opening a file" New topic
Author

Opening a file

Jennifer Sohl
Ranch Hand

Joined: Feb 28, 2001
Posts: 455
Hi there! I currently have an app that a user can right click on a part number to view an image. Currently what I am doing, is creating the file path (I have a file in DB2 that ,depending on the type of part number, has the directory that the image would be located in), then appending the file name and file extension. I am using the "cmd /c" to open up the default viewer for the file extension (using Runtime class). Is there a better way to do this? I don't want to have to tell my program what the file extension is, as different images are in different formats. How can I detect the file extension and have the correct default viewer open for it?

Sorry if I've confused anyone. If you need any further details or clarification, please let me know. Thanks for any help you can give me!
Jeff Albertson
Ranch Hand

Joined: Sep 16, 2005
Posts: 1780
Have you considered using Java to display the image?


There is no emoticon for what I am feeling!
Jennifer Sohl
Ranch Hand

Joined: Feb 28, 2001
Posts: 455
No, I have not. Currently the users are expressing they need an image viewing solution that has an explorer on the side,as well as the ability to view all file formats (includes excel, ppt, word, pdf..), and the ability to view thumbnails. But I am intrigued... can I do all of that within java? Haven't really explored that side of the language yet.
Jeff Albertson
Ranch Hand

Joined: Sep 16, 2005
Posts: 1780
By images I thought you meant images -- jpeg, png etc... Now you start mentioning Microsoft's different document formats, and you're getting into sticky areas that make me wonder why you're writing any part of this in Java...
Jennifer Sohl
Ranch Hand

Joined: Feb 28, 2001
Posts: 455
Basically what I want, is viewing software, that is capable of viewing pretty much all image and text type documents. We currently have an application that does that (we want to keep it, so they only have one program that allows them to view all different file types with it) . That same application is set as the default viewer for all image type files (.pdf included) . Through the java app, users will only be trying to view image type documentsk by right clicking on a part number to view the drawing of it. I need to know, how do I launch my default viewer without having to specify the file extension. this is what I am running now:

... which launches the viewer fine. But say the next part number doesn't have a .tif extension, but a .pdf extension... I have to hardcode in the program the file extension so it will open. What I want to do is something like this:

and have it automatically detect what type of a file it is, and open the correct default viewer that windows is set to.

Sorry if I've confused you again... this is hard for me to explain!
Thanks for the replies :-)
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
put the selected file into a variable and use that

String fileName = [set from right-click on part number];
"cmd \c "+fileName
note the 'space' after \c
Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4121

Check out the JDIC (Java Desktop Integration Components) project - especially the FileExplorer example and the org.jdesktop.jdic.filetypes package. This won't go as far as launching the associated application - you'd have to do that, much as you do now - but at least it would provide a framework for this type of thing.

You may also want to look into SWT - I know that it provides some ActiveX/OLE integration for Windows.
[ June 19, 2006: Message edited by: Nathan Pruett ]

-Nate
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
 
Don't get me started about those stupid light bulbs.
 
subject: Opening a file