标签:users while 必须 dex string system 选择 缓冲 cat
byte[] flush =new byte[n] //字节数组充当缓冲容器public static void main(String[]args)
{
//创建源
File f=new File("C:/Users/10853/eclipse-workspace/hell/src/hell/abc");
InputStream is =null;
//选择流
try {
is =new FileInputStream(f);
//操作(读取),分段读取
byte[] flush =new byte[3]; //缓冲容器
int len=-1; //接收长度
while((len=is.read(flush))!=-1) //is.read(car)每次读取三个字节,读取完毕会返回-1,
//当数据不够3时,将返回实际数据个数
{
String s =new String(flush,0,len); //必须返回实际的大小,否则多余的长度会返回垃圾字符
System.out.println(s);
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally
{
try {
if(null!=is)
{
is.close();
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
标签:users while 必须 dex string system 选择 缓冲 cat
原文地址:https://blog.51cto.com/14437184/2423102