Results 1 to 6 of 6
Thread: [Ask] change home directory
- 02-09-2011, 08:06 AM #1
Member
- Join Date
- Jan 2011
- Location
- Bandung, Indonesia
- Posts
- 6
- Rep Power
- 0
- 02-09-2011, 08:28 AM #2
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,545
- Rep Power
- 11
What is a "home directory"?
- 02-09-2011, 08:39 AM #3
Member
- Join Date
- Jan 2011
- Location
- Bandung, Indonesia
- Posts
- 6
- Rep Power
- 0
its how i call default directory where you save your file from your java application
sorry tho im kinda new in java
- 02-09-2011, 09:02 AM #4
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,545
- Rep Power
- 11
its how i call default directory where you save your file from your java application
sorry tho im kinda new in java
No need to be sorry - I was just wondering what you meant.
Here's what the File API docs have to say about it. "A pathname, whether abstract or in string form, may be either absolute or relative. An absolute pathname is complete in that no other information is required in order to locate the file that it denotes. A relative pathname, in contrast, must be interpreted in terms of information taken from some other pathname. By default the classes in the java.io package always resolve relative pathnames against the current user directory. This directory is named by the system property user.dir, and is typically the directory in which the Java virtual machine was invoked."
Basically it is saying that a "bare" name will usually be resolved with respect to whatever directory the program is run from. More exactly it will use the value of user.dir
(There is also a user.home property, but it's different)
We can, of course, put the file anywhere we want: either by actually specifying the location absolutely, or by changeing the value of user.dir
Perhaps the code example will make it clear. Ask if not
Java Code:import java.io.File; public class Foo { public static void main(String[] args) { // Fred is in the directory where the program was launched System.out.println(new File("fred").getAbsolutePath()); // We change "user.dir" and Fred ends up in the new location System.setProperty("user.dir", "C:\\windows"); System.out.println(new File("fred").getAbsolutePath()); // We specify Fred's location whereever we want it System.out.println(new File("H:\\documents\\fred")); // We put Fred in the users home directory // Different operating systems will be different but the // home is typically the place where the user puts their stuff System.out.println(new File(System.getProperty("user.home"), "fred")); } } output (for me): Y:\UserManagement\2011\eclipse\Users\fred C:\windows\fred H:\documents\fred C:\Documents and Settings\pbrockway.GHS\fred
- 02-11-2011, 08:39 AM #5
Member
- Join Date
- Jan 2011
- Location
- Bandung, Indonesia
- Posts
- 6
- Rep Power
- 0
thank you very much
- 02-11-2011, 10:07 PM #6
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,545
- Rep Power
- 11
Similar Threads
-
How can I change a project's build directory?
By sylvpan in forum NetBeansReplies: 11Last Post: 02-03-2011, 06:18 AM -
ow to get Home directory using Common Net ftp api?
By cprash.aggarwal in forum Advanced JavaReplies: 1Last Post: 03-01-2009, 05:57 PM -
How to get Home directory using Common Net ftp api?
By cprash.aggarwal in forum NetworkingReplies: 1Last Post: 03-01-2009, 05:37 PM -
Make money from home, Home Typing Data Entry Partnerships
By arturmoniswork in forum Reviews / AdvertisingReplies: 0Last Post: 12-30-2008, 05:55 AM -
[SOLVED] Can't change JDK directory.
By JavaNewbie0000 in forum New To JavaReplies: 8Last Post: 07-31-2008, 06:02 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks