웹 개발

Get the Current Working Directory in Java

노루아부지 2021. 8. 1. 00:14
  • Method 1
    String userDirectory = System.getProperty("user.dir");
    System.out.println("path : " + userDirectory);​
  • Method 2
    String userDirectory = new File("").getAbsolutePath();
    System.out.println("path : " + userDirectory);​
  • Method 3
    이 방법은 JDK 7 이상에서 동작합니다.
    String userDirectory = FileSystems.getDefault()
      .getPath("")
      .toAbsolutePath()
      .toString();
    System.out.println("path : " + userDirectory);​
  • Method 4
    이 방법 또한 JDK 7 이상에서 동작합니다.
    String userDirectory = Paths.get("")
      .toAbsolutePath()
      .toString();
    System.out.println("path : " + userDirectory);​

 

 출처 : https://www.baeldung.com/java-current-directory

 

728x90
loading