Java, windows: Get process name of given PID

If you use Java 10 or above, the enhanced process API can help you use PID to obtain the process name (Or other process information), such as:

import java.io.File;

class Scratch {
    public static void main(String[] args) {
        // Tips: In actual use, you should check whether the value of option exists. The process may have ended at the time of acquisition.

        // Obtain the processhandle corresponding to the process through the PID.
        ProcessHandle processHandle = ProcessHandle.of(6312).orElseThrow();
        // `processHandle.info().command()` will return the executable path of the process
        String command = processHandle.info().command().orElseThrow();
        System.out.println(command);
        // Using File, you can obtain the executable file information later,
        // or you can directly split the path to obtain the process name.
        // System.out.println(command.substring(command.lastIndexOf(File.separator) + 1));
        File exeFile = new File(command);
        System.out.println(exeFile.getName());
    }
}