class TestDemo1
{
public static void fileInputMethod()throws IOException
{
BufferedInputStream buffis
= new BufferedInputStream(new FileInputStream("ArraysDemo.java"));
int len = 0;
byte[] buf = new byte[5]; //定义一个大小为5的字节数组
while((len = buffis.read(buf))!=-1) // read每次都会从文件中取出5个字节放到数组中,直到最后返回-1时才停止。
{
System.out.print(new String(buf,0,len)); //注意此处用print而不是println
}
buffis.close();
}
public static void main(String[] args) throws IOException
{
fileInputMethod();
}
}
|