How to open an existing file from java

Hi Guys,
I have one problem Please help me in this.
How to open file(i.e. file can be any type, it is may be image file, doc file or pdf file) using java.
Even i tryed in one way but it is static way that is working in windows not for other OS.
Code :
import java.io.*;
public class CmdExec {
public static void main(String argv[]) {
try {
     DataInputStream din=new DataInputStream(System.in);
     System.out.println("Enter File Path to Open");
     String fName=din.readLine();
     File file=new File(fName);
Runtime.getRuntime().exec("rundll32 SHELL32.DLL,ShellExec_RunDLL " + file.getAbsolutePath());
catch (Exception err) {
err.printStackTrace();
If any other way to do please tell me.
Regards
Siva Prasad

Well, if the OS doesn't provide a mechanism to associate a file name with a certain program, there's nothing you can do.
I don't know whether something like JDIC can help you - otherwise, you'd have to find the solution for each OS. What's inside the exec()'s parenthesisses is not a Java problem anymore.

Similar Messages

  • How to open an PDF file from Java Application

    Hi
    I am developing a GUI application in java swing.
    on clicking one button, I want to open PDF file from my swing application.
    Is there any API through which I can achieve this?
    Tapan Maru
    Sun Certified Java Programmer

    Here's a way to do it (if I understand you
    correctly). Just let explorer.exe do it for you.
    import java.awt.*;
    public class openPDF
         Desktop desktop = Desktop.getDesktop();
         public openPDF()
              open("test.pdf");
         public void open(String path)
              try
                   Runtime.getRuntime().exec("explorer.exe "+path);
    } catch(Exception e) { System.out.println("NAI!
    I! ERROR!\n"+e); }
         public static void main(String[] args)
              openPDF myApplication = new openPDF();
    Why do you have a Desktop object as a member but instead of using it, you execute a command with Runtime (which is not platform independent!)???
    -Puce

  • How to open Adobe Reader file from another native IOS application?

    There is an existing thread, but I want to re-open it because I think this is an important feature that we need badly.  I was wondering if there is any plan to add this feature so we can open PDFs directly into Adobe from the web / other apps.
    How to open Adobe Reader file from another native IOS application?
    Basically, we just want to use a custom URL scheme to open a specific document in the App.  Currently, this only opens the app but does not load the file.
    APB

    Not to hijack the conversation but I can explain why this would be useful for both the above case and another.
    What I believe Pavel is talking about is setting up a "URL Scheme" for the Adobe Acrobat iOS application so that you can easily open a PDF specifically in Adobe Acrobat iOS from other native applications and even from web applications opened within Safari. This is particularly useful if your application requires some of the specific features in Adobe Reader iOS to grant them the best experience possible and you want to encourage this.
    Another case: If you're using Adobe Livecycle's document security modules (that encrypts PDF files so that Adobe Acrobat must "phone home" to decrypt and view the document), these PDF's can only be viewed inside the Adobe Acrobat application and appear as blank in most other PDF readers. Having a URL scheme allows your application utilising this functionality to have a 1 click step to view the PDF rather than the current non-user friendly process:
    - Within Safari, touch the PDF link (appears as blank in the default Safari PDF reader, which in itself is confusing)
      - Touch "Open in..."
      - Touch "Adobe Acrobat"
    We have an immediate need for this functionality for the example above. I can resubmit it in a separate post if necessary.

  • How to call a .bat file from java code?

    How to call a .bat file from java code? and how can i pass parameters to that .bat file?
    Thanks in advance

    thanks for ur reply
    but still i am getting the same error.
    I am trying to run a .bat file of together tool, my code looks like below
    import java.lang.Runtime;
    import java.lang.Process;
    import java.io.File;
    class SysCall{
         public static void main(String args[]){
              String cmd="D://Borland//Together6.2//bin//Together.bat -script:com.togethersoft.modules.qa.QA -metrics out:D://MySamples//Metrics// -fmt:html D://Borland//Together6.2//samples//java//CashSales//CashSales.tpr";
              //String path="D://Borland//Together6.2//bin//Together.bat ";
              Runtime r= Runtime.getRuntime(); //Declare the system call
              try{
                   System.out.println("Before batch is called");
                   Process p=r.exec(cmd);
                   System.out.println(" Exit value =" + p.exitValue());
                   System.out.println("After batch is called");
              /*can produce errors which must be caught*/
              catch(Exception e) {
                   e.printStackTrace();
                   System.out.println (e.toString());
    I am getting the below exception
    Before batch is called
    java.lang.IllegalThreadStateException: process has not exited
    at java.lang.Win32Process.exitValue(Native Method)
    at SysCall.main(SysCall.java:17)
    java.lang.IllegalThreadStateException: process has not exited

  • How to Read a CAB File from JAVA?

    Hi,
    Anyone knows how to read a CAB File from java. I need to read a property file of txt file that is packaged in CAB file & then based on that, I have to do processing. Is there anyway to do it.
    I had tried using java.util.zip.ZipFile Class, but it does work for JAR, but not for CAB.
    siva.

    Perhaps there's something in the Cabinet SDK that will help:
    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dncabsdk/html/cabdl.asp

  • How to open a brio Query from Java

    Hi,
    I am working with Hyperion Intellegence Explorer to take care of the MIS related activities, to pull out the Data from the Data Base and Export it to the Excel
    Actually this is a BAU.
    So i want to reduce my work burdon. I am a Java Progrrammer too. So i want to automate all the thing from Java.
    Pls help me below to open a Brio files from Java,so that i can proceed to process the Query and export it on to the Excel.,

    Don't double post the same question. You can continue in your previous thread
    [http://forums.sun.com/thread.jspa?threadID=5367120]
    I'm locking this one and it will be removed it later.
    db

  • How to open an InDesign file from CMIS repository?

    We are using CS SDK 2.0 , looking to use CMIS to keep versionning of .indd file. The uss case as following:
    form our de4veloped InDesign pluging, user click a button
    the button will open a .indd file from cmis repository
    plugin check-out the file, open it within InDesign IDE
    user make changes
    user make save
    the plugin export a pdf and swf files from the current document, if the files exists it will update, aslo on CMIS repo to keep also versions of exported pdf and swf, if files not exist in first time .. it will create
    when user clos the document , it will check it in.
    the problem there is no sufficent sample code for, even was thinking to use Adobe Drive, but there is no Adobe Drive SDK for Flex.
    i used to fuse the sdk, but
    private function getFileByPath(sPath:String):Fileable {
    appStatus = ">> get File By Path";
    message = "";
    viewEnabled = false;
    var request:GetObjectByPathRequest = new GetObjectByPathRequest(session);
    var oFileable:Fileable;
    request.path = sPath;
    request.execute(onSuccess, onError);
    function onSuccess (event:GetObjectByPathResponse) : void {
    oFileable = event.object;
    //var oDoc2:Document = new Document(event.object);
    doc = event.object as Document ;
    //children = new ArrayCollection(vectorToArray(event.target));
    appStatus = ">> getFileByPath : Success";
    viewEnabled = true;
    return oFileable;
    private function checkOutFile(oFile:Document):Document{
    appStatus = ">> Check Out File";
    message = "";
    viewEnabled = false;
    var request:CheckoutRequest = new CheckoutRequest(session);
    request.object = doc;
    var oDocument:Document;
    request.execute(onSuccess, onError);
    function onSuccess (event:CheckoutResponse) : void {
    oDocument = event.object ;
    appStatus = ">> Check Out File : Success";
    viewEnabled = true;
    return oDocument;
    private function openTestFile():void {
                                            appStatus = "Open Test File";
                                            message = "";
                                            viewEnabled = false;
                                            var oFile:Fileable  = getFileByPath("/Collaboration/test.indd");
                                            //var oDoc2:Document = new Document(oFile);
                                            var oDoc:Document  = checkOutFile(doc);
    i do not know what method in the CS SDK to open document fom active window and  how to map CMIS Document to com.adobe.indesign Document ?

    Dear Seoras
    i fixed the to return the cmis path:
    public function resolveRemotePath(file:File):String
                                  if (file.nativePath.indexOf(LOCAL_FILE_CACHE.nativePath) != 0)
                                            return null;
                                  var remoptePath:String =file.nativePath.substr(LOCAL_FILE_CACHE.nativePath.length);
                                  trace("resolveRemotePath [11] : "+ remoptePath);
                                  if(File.separator!="/") {
                                            //var pattern:RegExp = /(\/)/g;
                                            var pattern:RegExp = /(\\)/g;
                                            remoptePath =  remoptePath.replace(pattern ,"/");
                                            trace("resolveRemotePath [22] : "+ remoptePath);
                                  return remoptePath;
    i have another issue, why everytime update the generated pdf it creates new pdf file with same name in the cmis repo .. does the pdf is not updatable over the cmis service ???
    Regards

  • How to open a local file from javascript in a jsp-page

    Hi
    I have created an iview from a PAR file. In the par file I have a jsp-page with some javascript code. From the javascript coe I want to open a new window with an Excel file.
    I have tried window.open("c:
    test.xls", "test_window"), but it doesn't seem to work. I have created a small HTML page locally with the same command and there a new window opens with the Excel file.
    If I change the local file path with an URL it also works.
    Any idea how to open a local file ?
    Thanks
    /Jakob

    Jacob,
    I'm not 100% (but 99,9%) and it has to do with security ristrictions of the browser not allowing to have local workstation interation from the web. This is ofcourse very dangerous if the browser would allow it... So therfore it is blocked. What if somone would point to a file/executable that formats your drive so for that reason it is not allowed to have web interaction with a local file. Only with Java Applets this is possible but still with many limitations, and what I remember Google Gears and Adobe Air do have some limited web 2 local file interaction... So best and most simple solution you are left with is pointing to a url instead of a file on a c:\ drive.
    PS The reason why it works when you start the html from your local PC has todo with the fact that the browser detects that the html is not running in the web at that moment therefor allowing the access.
    Cheers,
    Benjamin Houttuin

  • Opening jpg/pdf files from Java

    Hi,
    How can I open jpg/pdf files or any file in general from Java, such that they open up in the default program in Windows?
    I dont want to read in the files using Java. Just open them in their default program. Eg. PDF should open in Adobe.
    thanks,
    parsifal

    Thanks both of you for answering.
    You don't need to make a map. You need the "cmd /c
    start" command in Windows.This is what I was missing. I looked up DOS commands to open a files in window but couldnt get it. So I thought java would have some command that equals double-clicking icons on window.
    Thanks.
    best,
    parsifal

  • How to open a BUP file from a flashdrive in Macbookair?

    Pl let me know how to view a video with BUP extension from a flashdrive in my macbookair?

    You can open a PUB file ONLY with MS Publisher (Windows). No other possibility.

  • How to open a web browser from java

    Hi
    Would anybody please help me with this. I need to open a web browser from my java app but I don't know. What method I can use?
    Thanks.
    Hung.

    You can use the Runtime class for this. It can run any command. So, you can run the .exe file of your Web browser.
    The following code will run Internet Explorer (assuming iexplorer.exe is in C:\Program Files\Internet Explorer):
    import java.lang.Runtime;
    public class Explore{
    public static void main(String[] args) {
    try{
    Process p = Runtime.getRuntime().exec("C:\\Program Files\\Internet Explorer\\iexplore");
    }catch (Exception e) {
    System.out.println("Exception: " + e);

  • How to open/convert RAW- files from new CANON 5D Mk III in LR 3 and CS 5?

    Hallo!
    The RAW- files from my new CANON 5D Mk III are not convertible into LR 3 and CS 5.
    What is the reason and how to solve the problem?

    The work around of converting the CR2 to dng either with the dng converter or ACR 6.7 will allow working in LR and CS5 but not with the latest raw conversion engine from Adobe i.e PV 2012.
    Remember to keep a copy of the CR2 files if you wish to utilize the Canon software.

  • How to open Microsoft office files from my wp8 app?

    Is there any way to open Microsoft office documents? I want to open a doc file which is in my phone.My app may try to open pdf also. So is there any way for that? I need a free one.

    //where file is your StorageFile type object of perticular //Office documents i.e. ppt or doc etc
    await Windows.System.Launcher.LaunchFileAsync(file);
    Please Refer these links 
    How to open pdf file in Windows Phone 8?
    Launcher.LaunchFileAsync
    shah
    // Please Mark as answer if it is Helpful to you. Thank You

  • How to open an excel file from labview?

    I tried to use "open file" vi from File I/O -- Advanced file functions to open an excel file in LabVIEW. Why the excel file wouldn't open after I run the program?

    In addition to ActiveX, you can also manipulate Excel data files using the Windows ADO interface - a technique that is more robust, faster and IMHO easier. Do a search on the forum as there have been several threads within the last week or so discussing this very thing.
    Mike...
    Certified Professional Instructor
    Certified LabVIEW Architect
    LabVIEW Champion
    "... after all, He's not a tame lion..."
    Be thinking ahead and mark your dance card for NI Week 2015 now: TS 6139 - Object Oriented First Steps

  • How to open a html file from hard disk

    Hello everyone,
    i want to display a html file by using java applet.
    This is my current coding:
    package mkbe.pg;
    import java.net.*;
    import java.applet.*;
    public class HtmlReader extends Applet 
    URL userUrl;
    public void start()
    try{
    userUrl = new URL(getDocumentBase(),"FILE:///c://2007/index.htm");
    }catch(MalformedURLException error){
    System.out.println("Error");
    getAppletContext().showDocument(userUrl,"_blank");
    }the program have no error and warning and the applet did run by appletviewer but the html file did'nt open.
    Is it there's mistake in my coding?
    If there is please tell me how to repair it.
    Thanks

    For an applet to read from a client's harddrive it will need permission.
    This can be done by putting the applet in a jar file and signing it,
    or by using the poiclytool to change the java.policy file to give FilePermission.

Maybe you are looking for

  • Is iTunes the worst software ever!!!!

    I have just purchased a new iPod shuffle, the new tiny one, which looks great and does the job. BUT the iTunes software is absoulte PANTS. Yes its that bad i used capital letters. Why cant they make it like Microsoft software where you can drag and d

  • MSI PRO e DEAD ?!?

    Hi, Under is my post from tech powerup. So as last thing I post it on your forum. Quote Hi, I need some advice what to do ... Today, I turned on my pc (see specs watched some news, facebook ,etc.) I noticed that I have 1 left FAN for my PC from work

  • [solved] problems with opencv

    I am trying to use some of the opencv libraries and seem to be unable to use opencv functions during the program execution. I built and installed opencv 1.1pre1-2 from AUR without any issue using the exact PKGBUILD. This is what happens when I run an

  • Form Based authentcation in Sharepoint 2010

    Hi,    I am Having a problem. everytime i enter the URL for accesing the site i am getting a new page which asks me whether i have to use forms based autherntication or Windows based authentication.Attaching the below screen shot of the same. can som

  • Bold 9700 Charging Pod doesn't Sync

    Hi, On ShopBlackberry.com, I came across this for the Bold 9700: http://www.shopblackberry.com/_blackberryaccessoriescan/cgi-bin/pd.cgi?frompage=category&page=produc... Where, under the features, it says:  Features Combines with any travel or data ca