How to open any file using java

We need File and Desktop modules for this program

import java.awt.*;
import java.io.File;
import java.io.IOException;

public class OpenFile {
    public static void main(String args[]) {
        File f = new File("filepath.exe");
        Desktop d = Desktop.getDesktop();
        try {
            d.open(f);
        } catch (IOException i) {
            System.out.println(i);
        }
    }
}

Comments

Popular posts from this blog

Personalized File Manager (in development)

Multimedia search engine using python

How to sort String array by length of each string present in an array