Results 1 to 8 of 8

Thread: java not reconizing path to desktop

  1. #1
    Join Date
    Mar 2011
    Location
    here, or there
    Beans
    31
    Distro
    Ubuntu 11.04 Natty Narwhal

    java not reconizing path to desktop

    im writing a program to move files in java from the desktop to another .jar file. When i use /home/user/Desktop as my path it doesn't recognize the path, but when i use my own system username it works just fine. How can i fix this?

  2. #2
    Join Date
    Nov 2009
    Location
    The Netherlands
    Beans
    239
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: java not reconizing path to desktop

    you can use System.getenv() to find the username that you have to use, or you can replace /home/user by a ~

  3. #3
    Join Date
    Feb 2007
    Location
    St. Louis, MO
    Beans
    4,930
    Distro
    Ubuntu 20.04 Focal Fossa

    Re: java not reconizing path to desktop

    A way to get to your Desktop in Java:

    Code:
    String userDesktop = System.getProperty( "user.home" ) + File.separator + "Desktop";
    This will display only the currently logged in users desktop.
    Last edited by stchman; July 27th, 2011 at 11:38 PM.
    Windows, only good for gaming.

  4. #4
    Join Date
    Mar 2011
    Location
    here, or there
    Beans
    31
    Distro
    Ubuntu 11.04 Natty Narwhal

    Re: java not reconizing path to desktop

    stchman does your method of finding the desktop also work on windows and mac because i need this program to be cross platform

  5. #5
    Join Date
    Feb 2007
    Location
    St. Louis, MO
    Beans
    4,930
    Distro
    Ubuntu 20.04 Focal Fossa

    Re: java not reconizing path to desktop

    Quote Originally Posted by <(-.-)> View Post
    stchman does your method of finding the desktop also work on windows and mac because i need this program to be cross platform
    AFAIK.

    Desktop is the name of the desktop on my Windows(XP and Vista) and Linux machines. If Desktop is used in OS X, then it is golden.
    Windows, only good for gaming.

  6. #6
    Join Date
    Jan 2005
    Location
    South Africa
    Beans
    2,098
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: java not reconizing path to desktop

    You can always try to find the OS and version. Never tried it in java, but in Tcl it's possible. Set the correct path based on the result.
    If you don't make backups of your important data, your data is obviously not important to you.

  7. #7
    Join Date
    Mar 2011
    Location
    here, or there
    Beans
    31
    Distro
    Ubuntu 11.04 Natty Narwhal

    Re: java not reconizing path to desktop

    Thanks pretty much I'm just trying to get the current username out of this code so I can input it into a couple of paths not really trying to go to the desktop with final product. And finding the os you look for the index of win, nux, ect. In the name.os file

  8. #8
    Join Date
    Feb 2007
    Location
    St. Louis, MO
    Beans
    4,930
    Distro
    Ubuntu 20.04 Focal Fossa

    Re: java not reconizing path to desktop

    Quote Originally Posted by <(-.-)> View Post
    Thanks pretty much I'm just trying to get the current username out of this code so I can input it into a couple of paths not really trying to go to the desktop with final product. And finding the os you look for the index of win, nux, ect. In the name.os file
    If you wanted the users name easy:

    Code:
    String userName = System.getProperty( "user.name" );
    Visit the System portion of the Java API.

    http://download.oracle.com/javase/6/...ng/System.html
    Windows, only good for gaming.

Bookmarks

Posting Permissions

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