package exceltest;
import java.io.FileInputStream;
import java.io.IOException;
/**
* 字节流读取汉字
* */
public class inputTest {
public static void main(String[] args) {
String filepath = "C:\\Users\\ybb\\Desktop\\test.txt";
byte[] b = new byte[18];
int readlen = 0;
FileInputStream fileInputStream = null;
try {
fileInputStream = new FileInputStream(filepath);
while ((readlen = fileInputStream.read(b)) != -1) {//读取到-1,表示读取完毕
System.out.print(new String(b, 0, readlen));//从0开始读,一直读到readlen长度
}
} catch (IOException e) {
e.printStackTrace();
}finally {
try {
fileInputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
Java笔记总结(三十三)---FileInputStream&按字符读取文件
最新推荐文章于 2024-04-27 17:30:34 发布