哥们,首先,读的方法使肯定要跑异常的,这个可能已经定义在你的方法签名后边了。按照你的代码的意思,使用了available()这个函数,代表你要一次就读完数据,将所读的数据全部存储到缓冲区byte字节数组中。但是读的方法有一个特点,它会自动去找磁盘中的下一个区域,读完时会自动返回一个-1,所以读的方法需要单独做控制。我接着你的代码来写。 byte[] b = new byte[in.available()]; String result = ""; in.read(b); result = new String(b); int len = 0;//len变量用于记录读取的字节数,读到结尾会返回-1 while((len=fis.read(buf))!=-1){ result = new String(buf); } 这样应该就行了。
你看看这个。你转换下试试。
byte[] b = new byte[in.available()]; String result = ""; in.read(b); result = new String(b);
int len = 0;//len变量用于记录读取的字节数,读到结尾会返回-1
while((len=fis.read(buf))!=-1){
result = new String(buf);
}
这样应该就行了。