关于File()中的pathname的路径

由于学习javase时不够认真,现在得再补一下Io流的知识。

public static void main(String[] args) throws IOException {
        File file = new File("333.jpg");		//这里是读取不到文件的
        FileInputStream inputStream = new FileInputStream(file);
}

上面是一个main方法
这是图片文件所在位置
以上方法中pathname直接填了文件名。是相对路径,但main方法中的相对路径是相对工作目录的,而当前的工作目录是。

    public static void main(String[] args) throws IOException {
        File file = new File("333.jpg");
//        输出 C:\Users\home\IdeaProjects\workspace
        System.out.println(System.getProperty("user.dir"));

    }

当前工作目录是对应当前工程下。而图片文件在工程目录下。所以正确的pathname是atcrowdfunding05-common-util\\333.jpg
另外关于test测试类中的相对路径。

@Test
    public void test1(){
//        C:\Users\home\IdeaProjects\workspace\atcrowdfunding05-common-util
        System.out.println(System.getProperty("user.dir"));
    }

test测试类中工作目录是当前module。所以相对路径也是当前模块下。

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值