欢迎光临散文网 会员登陆 & 注册

java关于路径的代码

2020-04-22 21:35 作者:小垃圾kiki  | 我要投稿
package cn.jd.server.basic;

import java.io.File;
import java.io.IOException;

public class HelloWorld {
    public static void main(String[] args) throws IOException {
        System.out.println(System.getProperty("user.dir"));//这是得到工程的路径
        String path="E:\\myjavacode\\Server_study01\\src\\cn\\jd\\server\\basic\\p.xml";
        File src=new File(path);
        System.out.println(src.getAbsolutePath());//获得绝对路径
//        System.out.println(src.getCanonicalPath());
        String filePath = "src/1.txt";
        File file = new File(filePath);
        System.out.println(file.exists());
                 
        try {
           file.createNewFile();
        } catch (IOException e) {
           e.printStackTrace();
        }
        
        System.out.println(file.exists());

    }
}

java关于路径的代码的评论 (共 条)

分享到微博请遵守国家法律