MrMcAero
|
  |
| Joined: 21 Apr 2012 |
| Total Posts: 671 |
|
|
| 04 May 2012 03:22 PM |
So..
I'd like to use mkdir() to make a file on the current user's Desktop. My only problem is I don't know how to get the path to the user's Desktop without having them put their username or something in. Anyone know?
Code (Just a simple mkdir(); function):
import java.io.*;
public class Filemkdir { public static void main(String[] args) { File f = new File("C:/hello"); f.mkdir(); } }
- Cheers! |
|
|
| Report Abuse |
|
|
MrMcAero
|
  |
| Joined: 21 Apr 2012 |
| Total Posts: 671 |
|
|
| 04 May 2012 03:23 PM |
How can I have the new file go to here for instance:
C:\Users\<Online User/YOU>\Desktop
- Cheers! |
|
|
| Report Abuse |
|
|
|
| 04 May 2012 03:26 PM |
File f = new File("%userprofile%/Desktop/hello");
Try that? |
|
|
| Report Abuse |
|
|
MrMcAero
|
  |
| Joined: 21 Apr 2012 |
| Total Posts: 671 |
|
|
| 04 May 2012 03:34 PM |
Didn't work. :\
(Maybe it's because I was in test mode and didn't compile the program to the real thing?)
- Cheers! |
|
|
| Report Abuse |
|
|
|
| 04 May 2012 03:35 PM |
| No clue. Heck, I'm not even sure if Java has access to Windows system environment variables. You could try looking through the FileSystem class; there may be special directory fields in it. |
|
|
| Report Abuse |
|
|
MrMcAero
|
  |
| Joined: 21 Apr 2012 |
| Total Posts: 671 |
|
|
| 04 May 2012 03:38 PM |
Got it.
Use a this:
System.getProperty("user.name");
I can get the name of the current user. With that, I can turn that to a string, and then do a simple [ Path + String_Name + Rest of path]
- Cheers! |
|
|
| Report Abuse |
|
|