import java.io.*;
public class FileInputStreamDemo
{ public static void main(String args[])
{ try
{ InputStream fileInput = new FileInputStream (
"d:/net_program/src/ch2/prog.java") ;
int data = fileInput.read();
while (data != -1) // Repeat : until end of file
{ System.out.write ( data );
data = fileInput.read(); }
fileInput.close(); }
catch (IOException ioe)
{ System.err.println ("I/O error - " + ioe); } }
}
程序中为什么再出现“data = fileInput.read(); ”,我删除后出现不会结束的同一个字码,再data前加int,和前面的的一样的时候,出现错误。到底这个貌似重复了的句子有什么用处?难道这里data和括号外的data是不一样的?还有data不是属于int型吗,怎么会实现打出prog.java里的所有字符。
public class FileInputStreamDemo
{ public static void main(String args[])
{ try
{ InputStream fileInput = new FileInputStream (
"d:/net_program/src/ch2/prog.java") ;
int data = fileInput.read();
while (data != -1) // Repeat : until end of file
{ System.out.write ( data );
data = fileInput.read(); }
fileInput.close(); }
catch (IOException ioe)
{ System.err.println ("I/O error - " + ioe); } }
}
程序中为什么再出现“data = fileInput.read(); ”,我删除后出现不会结束的同一个字码,再data前加int,和前面的的一样的时候,出现错误。到底这个貌似重复了的句子有什么用处?难道这里data和括号外的data是不一样的?还有data不是属于int型吗,怎么会实现打出prog.java里的所有字符。
data前不能再加int是因为它已经被定义过了,所以在同一个区域不能被定义两次。其实他两个是一样的东西