IDEA相对路径问题

目录结构

image

代码

public class Main {
    public static void main(String[] args) {
        try(FileInputStream inputStream = new FileInputStream("test.txt")) {
                //使用read()方法进行字符读取
                System.out.println((char) inputStream.read());
            }catch (IOException e){
                e.printStackTrace();
        }
    }
}

运行结果

image

解决方法

修改运行配置,修改工作目录

修改前:

image

修改后:

image

posted @ 2022-03-26 11:13  当惜  阅读(452)  评论(0)    收藏  举报