My question is simple:
How can I open a JavaScript file with Google Chrome on a Mac computer using Java?
This is my code so far:
JOptionPane.showMessageDialog(null, "Please browse to Google Chrome!");
JFileChooser fc = new JFileChooser();
FileFilter ff = new FileFilter() {
public boolean accept(File pathname) {
if (pathname.isDirectory()) {
return true;
}
if (pathname.getName().toLowerCase().equals("chrome.exe") || pathname.getName().toLowerCase().equals("chrome.app")) {
return true;
}
return false;
}
@Override
public String getDescription() {
return "chrome.exe; chrome.app";
}
};
fc.setFileFilter(ff);
int returnVal = fc.showOpenDialog(null);
if (returnVal == JFileChooser.APPROVE_OPTION) {
try {
Runtime.getRuntime().exec("open " + fc.getSelectedFile().toURI() + " " + f.toURI());
} catch (Exception exxxx) {
JOptionPane.showMessageDialog(null, "Unknown exception occurred! It's: " + exxxx.toString() + "\n" + "fc.getSelectedFile().toURI()");
}
}
I have little to no Mac knowledge, but this code opens Google Chrome, Safari and Finder at once...