ctangent
asked on
Java.io.File doesn't understand tilde
In unix/linux, you can refer to a user's home directory like this:
~username
instead of
/home/username
I would like to use ~username, sense it is possible that the user's home directory would be at /home/username.
Java.io.File doesn't understand ~username; it only understands /home/username
Is there any solution, or am I stuck having to manually (in code) replace '~' with /home/username or the full path of the location of the user's directory?
Thank you for any help you can give.
~username
instead of
/home/username
I would like to use ~username, sense it is possible that the user's home directory would be at /home/username.
Java.io.File doesn't understand ~username; it only understands /home/username
Is there any solution, or am I stuck having to manually (in code) replace '~' with /home/username or the full path of the location of the user's directory?
Thank you for any help you can give.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
CEHJ,
"user.home" won't work because the username I'd be working with might not be the username that the system property returns
sciuriware,
That makes sense. Thank you for your help.
"user.home" won't work because the username I'd be working with might not be the username that the system property returns
sciuriware,
That makes sense. Thank you for your help.
>>"user.home" won't work because the username I'd be working with might not be the username that the system property returns
That would be no different from ~
That would be no different from ~
ASKER
CEHJ,
Ahh. What I mean is that lets say I have the users bfee and rfoo.
On the unix machines their home dirs are /home/bfee and /home/rfoo. I can access them in unix by ~bfee and ~rfoo. But Java.io.File doesn't understand ~bfee, only /home/bfee.
When you say:
String homeDir - System.getProperty("user.h ome")
Do you mean literarlly
System.getProperty("user.h ome")
Or could I feasibly do:
System.getProperty("bfee.h ome")
System.getProperty("rfoo.h ome")
I have seen the "user.home" property, and am assuming that this just gets the home directory of the current user using the program. But in this case, the Java.io code is going into a servlet, so the technical user is tomcat.
Ahh. What I mean is that lets say I have the users bfee and rfoo.
On the unix machines their home dirs are /home/bfee and /home/rfoo. I can access them in unix by ~bfee and ~rfoo. But Java.io.File doesn't understand ~bfee, only /home/bfee.
When you say:
String homeDir - System.getProperty("user.h
Do you mean literarlly
System.getProperty("user.h
Or could I feasibly do:
System.getProperty("bfee.h
System.getProperty("rfoo.h
I have seen the "user.home" property, and am assuming that this just gets the home directory of the current user using the program. But in this case, the Java.io code is going into a servlet, so the technical user is tomcat.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
So, ............... you got to code it by hand some way.
;JOOP!
;JOOP!
I know of only one solution:
Make a map from /etc/profile.
The key is the first field, the value is the pre-last field: the home directory.
;JOOP!
Make a map from /etc/profile.
The key is the first field, the value is the pre-last field: the home directory.
;JOOP!
ASKER
What do you mean by "Make a map from /etc/profile"?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Sciuriware,
Thank you for your help!
Thank you for your help!
:<)
String homeDir - System.getProperty("user.h