현재 작업 디렉토리를 얻을순 없을까요???
조회수 10378회
소스코드
String current = new java.io.File( "." ).getCanonicalPath();
System.out.println("Current dir:"+current);
String currentDir = System.getProperty("user.dir");
System.out.println("Current dir using System:" +currentDir);
제 코드인데 결과가
Current dir: C:\WINDOWS\system32
Current dir using System: C:\WINDOWS\system32
이렇게 나와요 근데 이건 아니에요 왜냐면 C드라이브는 현재 폴더가 아니거든요... 도와주세요
1 답변
-
public class JavaApplication1 { public static void main(String[] args) { System.out.println("Working Directory = " + System.getProperty("user.dir")); } }
이렇게 하면 프로그램이 깔린곳의 전체 주소가 출력될겁니다.
만약 안되면
http://docs.oracle.com/javase/tutorial/essential/io/pathOps.html 여기 한번 참고해 보시고
java.nio.file.Path
랑java.nio.file.Paths
를 쓰시면 님의 현재 작업 디렉토리를 볼 수 있을겁니다.Path currentRelativePath = Paths.get(""); String s = currentRelativePath.toAbsolutePath().toString(); System.out.println("Current relative path is: " + s);
이렇게 했을때 제 클래스에선
Current relative path is: /Users/george/NetBeansProjects/Tutorials
이런 출력값이 나옵니다.
댓글 입력