tl  tr
  Home | Tutorials | Articles | Videos | Products | Tools | Search
Interviews | Open Source | Tag Cloud | Follow Us | Bookmark | Contact   
 Java > IO > Current Working Directory

Current Working Directory 

The following example shows how to access the current working directory or present working directory.

File Name  :  
com/bethecoder/tutorials/io/CurrentWorkingDirectory.java 
Author  :  Sudhakar KV
Email  :  [email protected]
   
package com.bethecoder.tutorials.io;

import java.io.File;
import java.util.Date;


public class CurrentWorkingDirectory {

  /**
   @param args
   */
  public static void main(String[] args) {

    File curDir = getCurDirectoryFile();
    System.out.println("Current working directory : " + curDir);
    System.out.println("Current working directory last modified on : " 
        new Date(curDir.lastModified()));

  }

  public static File getCurDirectoryFile() {
    return new File(getCurDirectory());
  }

  public static String getCurDirectory() {
    return System.getProperty("user.dir");
  }

}
   

It gives the following output,
Current working directory : C:\io_tests
Current working directory last modified on : Mon Apr 18 15:52:20 IST 2011



 
  


  
bl  br