当前位置: 代码迷 >> J2SE >> 关于FileInputStream的有关问题
  详细解决方案

关于FileInputStream的有关问题

热度:136   发布时间:2016-04-24 02:10:56.0
关于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");
  相关解决方案