Friday, August 26, 2011

Open file with default program

In my example I have pdf file that I want to be opened as soon as it is saved to disk.


public static void openFile(File fileObj)
{
    StringBuilder sb = new StringBuilder();
    sb.append("cmd.exe /C start ");
    sb.append(fileObj.getAbsolutePath());
    System.out.println("openFile: " + sb);
    try
    {
        Runtime.getRuntime().exec(sb.toString());
    }
    catch (IOException e)
    {
        System.out.println("EEExxxccc");
    }
    }

No comments:

Post a Comment