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

How to check if two Strings are anagrams of each other?

Multimedia search engine using python

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