Java代码如何获取当前工作目录呢?
下文笔者讲述Java代码获取当前工作目录的方法分享,如下所示:
实现思路:
使用以下代码,即可返回当前工作目录
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);
例:
package com.java265.other;
import java.io.IOException;
public class test {
/*
* java265.com 获取当前工作目录的示例分享
*/
public static void main(String[] args) throws IOException {
String current = new java.io.File(".").getCanonicalPath();
System.out.println("当前工作目录:" + current);
String currentDir = System.getProperty("user.dir");
System.out.println("当前工作目录:" + currentDir);
}
}
版权声明
本文仅代表作者观点,不代表本站立场。
本文系作者授权发表,未经许可,不得转载。


