日期:2014-05-20  浏览次数:20859 次

关于FileInputStream的问题
Java code

public class FileInputStreamTestDemo {
        public static void main(String[] args) throws IOException {
            FileInputStream fis=new FileInputStream("FileInputStreamTestDemo.java");
            byte [] b=new byte[1024];
            int hasRead=0;
            while((hasRead=fis.read())!=0){
                System.out.print(new String(b,0,hasRead));
            }
        }
}




异常:

Exception in thread "main" java.io.FileNotFoundException: FileInputStreamTestDemo.java (系统找不到指定的文件。)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(FileInputStream.java:106)
at java.io.FileInputStream.<init>(FileInputStream.java:66)
at FileInputStreamTestDemo.main(FileInputStreamTestDemo.java:8)


求解


------解决方案--------------------
这里要写绝对路径: 

FileInputStream fis=new FileInputStream("FileInputStreamTestDemo.java");

比如:
FileInputStream fis=new FileInputStream("c:/FileInputStreamTestDemo.java");