-1

Apologies if this has been asked, I can't seem to find the answer anywhere.

Here is my code:

private void OpenLogActionPerformed(java.awt.event.ActionEvent evt) {                                        
    Desktop dk = Desktop.getDesktop();
    try {
        dk.open(new File("C:\\Users\\Nick\\Desktop\\DropLogs\\Rex.txt"));        
    } catch (IOException ex) {
        Logger.getLogger(DropLogger.class.getName()).log(Level.SEVERE, null, ex);
    }
}

For the file path I'm looking for it to work for any drive letter and any user name, so that others can use the program. From what I've read it seems to be something like:

dk.open(new File("**\\Users\\*\\Desktop\\DropLogs\\Rex.txt"));

But that doesn't seem to be working. Any help is apprecaited

  • Well, There is a flaw in your logic, but let me ask this do you just want the current logged in users `Desktop->DropLogs` folder ? – Kenneth Clark Mar 12 '15 at 12:00
  • other user can use program on your machine or on theirs ?because you can never know other user's pc Directory Structure without asking them – Neeraj Jain Mar 12 '15 at 12:02
  • What about using the environment variable `%USERPROFILE%` for the user directory? Or `System.getProperty("user.home")` – SubOptimal Mar 12 '15 at 12:03
  • It was assuming that they have a "standard" structure since it's only friends that will be using it. – DivineShine Mar 12 '15 at 12:09

1 Answers1

0

You can use System.getProperty("user.home") to get the path to the user home so:

dk.open(new File(System.getProperty("user.home") "+/Desktop/DropLogs/Rex.txt"));

would do it.

agamesh
  • 559
  • 1
  • 10
  • 26
  • This just seems to open my user folder and not the specified one. – DivineShine Mar 12 '15 at 12:10
  • System.getProperty("user.home") will give you the path to the user home. If you run it will give you your user folder, but other users will get theirs. – agamesh Mar 12 '15 at 12:34