Good Morning everyone. Is it possible to open a file given the path, if it is closed, and if it is already open, putting the window in the foreground? This is the code to open the file:
package openapp;
import java.awt.Desktop;
import java.io.File;
import java.io.IOException;
import java.lang.IllegalArgumentException;
import java.util.Scanner;
public class OpenApp{
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
try {
if(!Desktop.isDesktopSupported()){
System.out.println("The desktop is not supported");
return;
}
Desktop desktop = Desktop.getDesktop();
System.out.println("Enter the path to the file to open");
String path = input.nextLine();
File file = new File(path);
desktop.open(file);
//il file non esiste
} catch (IllegalArgumentException e) {
System.out.println("the file does not exist");
} catch (IOException e) {
e.printStackTrace();
}
}
}
So the real question is: Is it possible to check if a file / app is already running and you can put a window in the foreground? (As an operating system I consider windows)