java.io.FileNotFoundException: 系统找不到指定的文件

java.io.FileNotFoundException: 系统找不到指定的文件

在指定路径下,项目路径下没有a.txt文件,报错。

public class CopyFileDemo {

    public static void main(String[] args) throws IOException {
        //创建输入流对象
        FileInputStream fis = new FileInputStream("a.txt");
        //创建输出流对象
        FileOutputStream fos = new FileOutputStream("b.txt");
        //创建字节数组
        byte[] bys = new byte[1024];
        int len = 0;
        //读取数据
        while ((len=fis.read(bys))!=-1){
            fos.write(bys,0,len);
        }
        //释放资源
        fis.close();
        fos.close();
    }
}

结果:

Exception in thread "main" java.io.FileNotFoundException: a.txt (系统找不到指定的文件。)
	at java.base/java.io.FileInputStream.open0(Native Method)
	at java.base/java.io.FileInputStream.open(FileInputStream.java:196)
	at java.base/java.io.FileInputStream.<init>(FileInputStream.java:139)
	at java.base/java.io.FileInputStream.<init>(FileInputStream.java:94)
	at com.ginger.demo07.CopyFileDemo.main(CopyFileDemo.java:11)

你可能感兴趣的:(Question)