用字节流查看txt文件

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;

public class Test01 {
public static void main(String[] args) throws FileNotFoundException {
FileInputStream fis=new FileInputStream("D:\\新建文件夹\\你若还在.txt");
byte[] bytes=new byte[1024];
/*try {
int date = fis.read(bytes);
String temp=new String(bytes, 0, date);
System.out.println(temp);
} catch (IOException e) {
e.printStackTrace();
}*/
//当别的文档输入时,之前文本文档内容被替换
try {
int date=fis.read(bytes);
while(date!=-1){
String temp=new String(bytes, 0, date);
System.out.println(temp);
date=fis.read(bytes);
}
} catch (IOException e) {
e.printStackTrace();
}
}
}

posted @ 2016-02-19 13:06  有点小优雅  阅读(823)  评论(0编辑  收藏  举报