자바 현재 경로 획득
System.out.println(System.getProperty("user.dir"));//user.dir 2.File 에서 제공 하 는 함수 로 현재 경 로 를 가 져 옵 니 다.
File directory = new File("");//
try{
System.out.println(directory.getCanonicalPath());//
System.out.println(directory.getAbsolutePath());//
}catch(Exceptin e){} File.getCanonicalPath()와 File.getAbsolutePath()는 대략 new File(".")과 new File("...")두 가지 경로 에 대해 차이 가 있 을 뿐이다.
\#getCanonicalPath()함수 에 대해"..."현재 폴 더 를 표시 하고"..."현재 폴 더 의 이전 폴 더 를 표시 합 니 다.
\#getAbsolutePath()함수 에 대해 서 는 상관 하지 않 습 니 다.","..."현재 경 로 를 되 돌려 주 고 new File()에서 설정 한 경 로 를 추가 합 니 다.
\#getPath()함수 에 대해 서 는 new File()에서 설정 한 경로 만 얻 을 수 있 습 니 다.
예 를 들 어 현재 경 로 는 C:\test:
File directory = new File("abc");
directory.getCanonicalPath(); // C:\test\abc
directory.getAbsolutePath(); // C:\test\abc
direcotry.getPath(); // abc File directory = new File(".");
directory.getCanonicalPath(); // C:\test
directory.getAbsolutePath(); // C:\test\.
direcotry.getPath(); // . File directory = new File("..");
directory.getCanonicalPath(); // C:\
directory.getAbsolutePath(); // C:\test\..
direcotry.getPath(); // .. 또한:System.getProperty()의 문자열 인 자 는 다음 과 같 습 니 다.
System.getProperty()
# java.version Java Runtime Environment version
# java.vendor Java Runtime Environment vendor
# java.vendor.url Java vendor URL
# java.home Java installation directory
# java.vm.specification.version Java Virtual Machine specification version
# java.vm.specification.vendor Java Virtual Machine specification vendor
# java.vm.specification.name Java Virtual Machine specification name
# java.vm.version Java Virtual Machine implementation version
# java.vm.vendor Java Virtual Machine implementation vendor
# java.vm.name Java Virtual Machine implementation name
# java.specification.version Java Runtime Environment specification version
# java.specification.vendor Java Runtime Environment specification vendor
# java.specification.name Java Runtime Environment specification name
# java.class.version Java class format version number
# java.class.path Java class path
# java.library.path List of paths to search when loading libraries
# java.io.tmpdir Default temp file path
# java.compiler Name of JIT compiler to use
# java.ext.dirs Path of extension directory or directories
# os.name Operating system name
# os.arch Operating system architecture
# os.version Operating system version
# file.separator File separator ("/" on UNIX)
# path.separator Path separator (":" on UNIX)
# line.separator Line separator ("
" on UNIX)
# user.name User's account name
# user.home User's home directory
# user.dir User's current working directory
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Is Eclipse IDE dying?In 2014 the Eclipse IDE is the leading development environment for Java with a market share of approximately 65%. but ac...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.