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?
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?
you can use System.getenv() to find the username that you have to use, or you can replace /home/user by a ~
A way to get to your Desktop in Java:
This will display only the currently logged in users desktop.Code:String userDesktop = System.getProperty( "user.home" ) + File.separator + "Desktop";
Last edited by stchman; July 27th, 2011 at 11:38 PM.
Windows, only good for gaming.
stchman does your method of finding the desktop also work on windows and mac because i need this program to be cross platform
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.
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:
Visit the System portion of the Java API.Code:String userName = System.getProperty( "user.name" );
http://download.oracle.com/javase/6/...ng/System.html
Windows, only good for gaming.
Bookmarks