Saturday 8 February 2014

java code for open any file programmatically



import java.io.File;

public class OpenAnyFile {

    public static void main(String[] args) {
        File ff = new File("C:\\Users\\Desktop\\sylabus.docx");
        open_files(ff.getAbsolutePath());
    }

    public static void open_files(String abspath) {
        try {
            Runtime r = Runtime.getRuntime();
            String path = "cmd.exe /c start \"\" /max \"" + abspath + "\"";

            System.out.println("path = " + path);

            Process p = r.exec(path);

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

No comments:

Post a Comment