关于获取当前工作目录的(求相对路径时会有用)

public class WorkingDirectoryExample {
    public static void main(String[] args) {
        // 获取当前工作目录
        **String workingDir = System.getProperty("user.dir");**
        System.out.println("当前工作目录: " + workingDir);
        
        // 使用相对路径创建文件
        File relativeFile = new File("data.txt");
        System.out.println("相对路径文件的绝对路径: " + relativeFile.getAbsolutePath());
    }
}
posted @ 2025-04-22 20:39  lfqyj  阅读(24)  评论(0)    收藏  举报