用字节流查看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();
}*/
//當別的文檔輸入時,之前文本文檔內(nèi)容被替換
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();
}
}
}
轉(zhuǎn)載于:https://www.cnblogs.com/zqsheng/p/5200676.html
總結(jié)
以上是生活随笔為你收集整理的用字节流查看txt文件的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。