I am making a Swing application for light local database management and I have the button Run XAMPP
.
When that button is pressed this code is executed:
private void jRunXAMPPButtonActionPerformed(java.awt.event.ActionEvent evt)
{
String[] paths = {"C:\\xampp\\xampp-control.exe",
"C:\\Program Files\\xampp\\xampp-control.exe",
"C:\\Program Files (x86)\\xampp\\xampp-control.exe"};
for (String path : paths) {
final File file = new File(path);
if (file.exists()) {
try {
Process p = Runtime.getRuntime().exec(file.getAbsolutePath());
} catch (IOException e) {
continue;
}
return;
}
}
Helper.printErrln("xampp-control.exe was not found or is corrupt!"); // Prints error in red
}
I basically have the three possible paths that xampp could be at and I go through them and check if the file exists and can be executed. If not then it prints the error that the file could not be found or is corrupt.
Do you have any tips for my code? Any better way of doing this and I'm especially concerned that my error handling is not that great.