Results 1 to 4 of 4
  1. #1
    xael is offline Member
    Join Date
    Sep 2010
    Posts
    31
    Rep Power
    0

    Default Getting User name for paths

    Is there a way to get the name of the user for a path? I want to make a program that can create/open/read files on any computer on which the program is run. As far as I know, paths are as follows (for Windows)
    Java Code:
    C:\Users\[username]\folder\file
    but this won't work without the username in question; so how can I get the name of the user running the program so I can use it in a path? Or is there a generic I can use instead?

    Thank you.

  2. #2
    xael is offline Member
    Join Date
    Sep 2010
    Posts
    31
    Rep Power
    0

    Default

    I realize that all backslashes in the code sample should be doubled, my bad

  3. #3
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,776
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by xael View Post
    I realize that all backslashes in the code sample should be doubled, my bad
    Yep, and to answer your question: look in the System.getProperties() method; the user name is in there (as well as its 'home' directory)

    kind regards,

    Jos

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,224
    Rep Power
    20

    Default

    Yep, "user.home" (I think, you'd do well to double check that) will give you the home directory, which seems to be what you want.

Similar Threads

  1. a little help with file paths
    By ashton in forum New To Java
    Replies: 3
    Last Post: 01-27-2009, 05:08 PM
  2. getting paths and directories
    By marco in forum Java Applets
    Replies: 3
    Last Post: 11-25-2007, 08:28 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •