Results 1 to 2 of 2
  1. #1
    Java Tip's Avatar
    Java Tip is offline Moderator
    Join Date
    Nov 2007
    Blog Entries
    Rep Power

    Default Static function to get current working directory

    The following static function can be used to get the current working director.
    Java Code:
        private static void doGetDir() {
            String curDir = System.getProperty("user.dir");
            System.out.println("\nThe current working directory is:");
            System.out.println("  - " + curDir);

  2. #2
    Nicholas Jordan's Avatar
    Nicholas Jordan is offline Senior Member
    Join Date
    Jun 2008
    Rep Power

    Default Uh,.. user home dir is cur dir?

    Only reading the code once, it appears to me to be getting user home directory. To get current dir would we not:
    Java Code:
    String currentDir = new File(".");
    And, as well, working dir and current dir may be somewhat misleading for inexperienced coders. Say runnable Java code with a properly written main() and so on is in /dir/dir/program.class and the code does File fidelus = new File("../dir/dir/drivel.dat"); or opens several files or tries to do some beginner blunder or ..... ( unthought of work goes here )

    Where did the concept of working dir go?....perhaps concept of working directory is of limited scope. If os supports multiple file handles open, concept of working directory is archaic.

Similar Threads

  1. How to get Current Directory through File
    By Java Tip in forum
    Replies: 0
    Last Post: 04-05-2008, 10:14 AM
  2. Static methods - not working
    By Echilon in forum New To Java
    Replies: 2
    Last Post: 12-21-2007, 01:31 PM
  3. Replies: 1
    Last Post: 08-07-2007, 05:05 AM
  4. How to get the current working directory in EJB?
    By sathish_2111 in forum Enterprise JavaBeans (EJB)
    Replies: 1
    Last Post: 07-19-2007, 04:24 PM
  5. How can i get current directory?
    By Ashley in forum New To Java
    Replies: 1
    Last Post: 05-26-2007, 01:21 PM

Posting Permissions

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