1717package de .doubleslash .keeptime .common ;
1818
1919import java .io .File ;
20+ import java .util .Arrays ;
2021
2122import org .slf4j .Logger ;
2223import org .slf4j .LoggerFactory ;
@@ -27,15 +28,15 @@ public class FileOpenHelper {
2728
2829 private FileOpenHelper () {}
2930
30- public static boolean openFile (final String fileString ) {
31- final File file = new File (fileString );
31+ public static boolean openFile (final String filePath ) {
32+ final File file = new File (filePath );
3233 final Runtime rt = Runtime .getRuntime ();
3334
3435 if (file .exists () && file .isFile ()) {
3536 if (OS .isWindows ()) {
36- executeCommandWindows (rt , file );
37+ openFileWindows (rt , file );
3738 } else if (OS .isLinux ()) {
38- executeCommandLinux (rt , fileString );
39+ openFileLinux (rt , filePath );
3940 } else {
4041 LOG .warn ("OS is not supported" );
4142 }
@@ -45,27 +46,25 @@ public static boolean openFile(final String fileString) {
4546 }
4647 }
4748
48- private static void executeCommandWindows (final Runtime rt , final File file ) {
49+ private static void openFileWindows (final Runtime rt , final File file ) {
50+ final String command = "rundll32 url.dll,FileProtocolHandler " + file ;
4951 try {
50- final String command = "rundll32 url.dll,FileProtocolHandler " + file ;
5152 LOG .debug ("executing command: {}" , command );
52-
5353 rt .exec (command );
5454 } catch (final Exception e ) {
55- LOG .error (e . getMessage () );
55+ LOG .error ("Could not open file '" + file + "' with command '" + command + "'." , e );
5656 }
5757 }
5858
59- private static void executeCommandLinux (final Runtime rt , final String fileString ) {
59+ private static void openFileLinux (final Runtime rt , final String filePath ) {
60+ final String [] command = {
61+ "xdg-open" , filePath
62+ };
6063 try {
61- final String [] command = {
62- "xdg-open" , fileString
63- };
64- LOG .debug ("executing command: {} {}" , command [0 ], command [1 ]);
65-
64+ LOG .debug ("executing command: {}" , Arrays .toString (command ));
6665 rt .exec (command );
6766 } catch (final Exception e ) {
68- LOG .error (e . getMessage () );
67+ LOG .error ("Could not open file '" + filePath + "' with command '" + Arrays . toString ( command ) + "'." , e );
6968 }
7069 }
7170}
0 commit comments