/**
* FileInputStream的使用
*/
package com.test2;
import java.io.*;
public class Demo11_2 {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
File f=new File("d:\\a.txt");
//因为文件没有读写能力,所以需要使用Inputstream
FileInputStream fis=null;
try {
fis=new FileInputStream(f);
byte bytes[]=new byte[1024];//定义字节数组,缓存
int n=0;//得到实际读取到的字节数
//循环读取
while ((n=fis.read(bytes))!=-1)
{
//把字节转换成String
String s=new String(bytes,0,n);
System.out.println(s);
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally
{
try {
fis.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}