码迷,mamicode.com
首页 > 其他好文 > 详细

用字节流查看txt文件

时间:2016-02-19 14:13:35      阅读:151      评论:0      收藏:0      [点我收藏+]

标签:

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();
}
}
}

用字节流查看txt文件

标签:

原文地址:http://www.cnblogs.com/zqsheng/p/5200676.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!