天天看點

檔案流輸出的例子

import java.io.*;

public class FileInputStreamDemo {

public static void main(String args[]) throws Exception{

int size;

InputStream f = new FileInputStream("FileInputStreamDemo.java");

System.out.println("Total Available Bytes: "+

(size = f.available()));

int n = size/40;

System.out.println("First "+n+" bytes of the file one read() at a time");

}

上面代碼報錯。。。

Exception in thread "main" java.io.FileNotFoundException: FileInputStreamDemo.java (系統找不到指定的檔案。)

at java.io.FileInputStream.open(Native Method)

at java.io.FileInputStream.<init>(Unknown Source)

at java.io.FileInputStream.<init>(Unknown Source)

at FileInputStreamDemo.main(FileInputStreamDemo.java:5)

進行如下改動之後可以正常運作。。。 InputStream f = new FileInputStream("src/FileInputStreamDemo.java");