Open windows explorer in java

I searched for the answer to this question in Stack Overflow, but I could not find the answer that worked for me.

Using Java, how to create a button that launches an explorer window in the specified directory? If possible, how can I make it work for OSX and Linux?

+6
source share
2 answers

I'm not sure how this works on another OS, but on Windows you can use something like this

Desktop.getDesktop().open(new File("c:\\")); 

Edit

Found another way (mark the link to the FileExplorer class from this answer). You can also use System.getProperty("os.name") to determine the operating system.

+14
source
 javax.swing.JButton myButton = new javax.swing.JButton("BUTTON TEXT"); myButton.addActionListener(new java.awt.event.ActionListener() { @Override public void actionPerformed(ActionEvent e) { java.awt.Desktop.getDesktop().open(new java.io.File("MY PATH NAME HERE")); } }); 
+2
source

Source: https://habr.com/ru/post/918846/


All Articles