//每次读取一个字节
try {
//文件输入流的对象一旦生成,那么这个流就是打开的。
FileInputStream fis = new FileInputStream("1.txt");
//每次只能读取一个字节 也有一个类似游标的东西。
//如果read 方法返回的是-1 表明该流读到末尾了。
byte temp[] = new byte[];
int result = fis.read();
//len 指的是 read 方法一次读取到的字节的数量。读取到末尾返回-1
// int len = fis.read(temp);
while (result != -){
System.out.print((char)result);
result = fis.read();
}
fis.close();
} catch (Exception e) {
e.printStackTrace();
}
//每次读取多个字节
public static void main(String[] args) {
try {
//文件输入流的对象一旦生成,那么这个流就是打开的。
FileInputStream fis = new FileInputStream("1.txt");
//每次只能读取一个字节 也有一个类似游标的东西。
//如果read 方法返回的是-1 表明该流读到末尾了。
byte temp[] = new byte[];
// char result = (char)fis.read();
//len 指的是 read 方法一次读取到的字节的数量。读取到末尾返回-1
int len = fis.read(temp);
while (len != -){
System.out.print(new String(temp,,len));
// result = (char)fis.read();
len = fis.read(temp);
}
fis.close();
} catch (Exception e) {
e.printStackTrace();
}
}