Results 1 to 6 of 6
  1. #1
    goklien is offline Member
    Join Date
    Jan 2011
    Location
    Bandung, Indonesia
    Posts
    6
    Rep Power
    0

    Default [Ask] change home directory

    anyone know haw to change home directory from java application?

  2. #2
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default

    What is a "home directory"?

  3. #3
    goklien is offline Member
    Join Date
    Jan 2011
    Location
    Bandung, Indonesia
    Posts
    6
    Rep Power
    0

    Default

    its how i call default directory where you save your file from your java application

    sorry tho im kinda new in java

  4. #4
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default

    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

  5. #5
    goklien is offline Member
    Join Date
    Jan 2011
    Location
    Bandung, Indonesia
    Posts
    6
    Rep Power
    0

    Default

    thank you very much

  6. #6
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

Similar Threads

  1. How can I change a project's build directory?
    By sylvpan in forum NetBeans
    Replies: 11
    Last Post: 02-03-2011, 06:18 AM
  2. ow to get Home directory using Common Net ftp api?
    By cprash.aggarwal in forum Advanced Java
    Replies: 1
    Last Post: 03-01-2009, 05:57 PM
  3. How to get Home directory using Common Net ftp api?
    By cprash.aggarwal in forum Networking
    Replies: 1
    Last Post: 03-01-2009, 05:37 PM
  4. Make money from home, Home Typing Data Entry Partnerships
    By arturmoniswork in forum Reviews / Advertising
    Replies: 0
    Last Post: 12-30-2008, 05:55 AM
  5. [SOLVED] Can't change JDK directory.
    By JavaNewbie0000 in forum New To Java
    Replies: 8
    Last Post: 07-31-2008, 06:02 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •