aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes How can I found paths to Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "How can I found paths to "My Computer", "Desktop", ... folders for the current user?" Watch "How can I found paths to "My Computer", "Desktop", ... folders for the current user?" New topic
Author

How can I found paths to "My Computer", "Desktop", ... folders for the current user?

Yehor Mikhaylov
Greenhorn

Joined: Dec 14, 2001
Posts: 17
Hello All.
I want to create more useful file open/save dialog that uses JfileChooser. I want to add links to �Desktop�, �My Computer�, �My Documents�, �My Pictures� and so on like on open dialog in WinXp.
How can I found paths to these folders for the current user?
Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4121

You could... but you'd have to make the file chooser pretty much from scratch (or look at the code for JFileChooser and change it...), and then it would only be specific to Windows XP!

For example, on my Windows 2000 box here at work, most of these files are kept in C:\Documents and Settings\<username>, but I know that these are kept somewhere completely different on my Windows 98 box at home. And my linux box has no idea what "My Documents" are?!?!

The System class provides a platform independent way to get the user's home directory (System.getProperty( "user.home" )), but I would leave it up to the user to go to "My Documents", "My Pictures", etc.
[ February 27, 2003: Message edited by: Nathan Pruett ]

-Nate
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
Dana Hanna
Ranch Hand

Joined: Feb 28, 2003
Posts: 227
on winxp and win2k you'd be safe saying this:
String home = System.getProperty("user.home");
String myDocs = home + "/My Documents";
String desktop = home + "/Desktop";
as far as my computer, you're screwed.
I'll re-inforce that you are losing all cross-platform capability here. Write the damn thing in VB.
Phil Chuang
Ranch Hand

Joined: Feb 15, 2003
Posts: 251
Couldn't you just check to see if you're running on a windows system and then add them in if applicable?
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: How can I found paths to "My Computer", "Desktop", ... folders for the current user?