62,614
社区成员
发帖
与我相关
我的任务
分享
import java.io.*;
class bufferInputStream {
public static void main(String[] args) throws IOException
{
try {
File file=new File("f:/work/file2.txt");
long len=file.length();
System.out.println("changdu" + len);
byte[] bytes = new byte[(int)len];
FileInputStream f=new FileInputStream(file);
BufferedInputStream bs=new BufferedInputStream(f);
while(bs.read()!=-1)
{
bs.read(bytes,0,((int)len));
System.out.println(new String(bytes));
}
bs.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
class BufferInputStream {
public static void main(String[] args) throws IOException {
try {
File file = new File("F:/work/file2.txt");
long len = file.length();
System.out.println("changdu:" + len);
byte[] bytes = new byte[(int) len];
FileInputStream f = new FileInputStream(file);
BufferedInputStream bs = new BufferedInputStream(f);
while (true) { //楼主的代码此处就读了一次数据
int key = bs.read(bytes, 0, ((int) len));
System.out.println(new String(bytes));
if (key == -1)
break;
}
bs.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
File file=new File("f:/work/file2.txt");
byte[] buf = new byte[1024];
int size = 0;
StringBuilder sb = new StringBuilder();
InputStream is = new FileInputStream(file);
while((size = is.read(buf)) != -1)
sb.append(new String(buf,0,size));
is.close();
System.out.println(sb.toString());