package rxxj;
import java.io.*;
public class Life {
public static void main(String[] args) {
String fileName = "D:/all/demo/day/src/rxxj/text.txt";
readFileByOneChar(fileName);
}
public static void readFileByOneChar(String fileName) {
File file = new File(fileName);
Reader reader = null;
try {
// 一次读一个字符
reader = new InputStreamReader(new FileInputStream(file));
int onechar;
while ((onechar = reader.read()) != -1) {
if (((char) onechar) != '\r') { //一次读一个字符,规避掉换行符
System.out.print((char) onechar);
}
}
} catch (Exception e) {
e.printStackTrace();
} finally {
if(reader != null){
try {
reader.close();//关闭输入流
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
}
结果