由于学习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。所以相对路径也是当前模块下。