import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
public class Notepad {
private static int line = 0; //行号
public static void main(String[] args) {
String filePath = "D://小说//第一集.txt";// 文件路径
File file = new File(filePath);
FileReader fr = null;
int lineNum = 50; // 每行多少个字
try {
fr = new FileReader(file);
fr.read();
BufferedReader read = new BufferedReader(fr);
while (read.read() != -1) {
String as = read.readLine();
readByLineNumber(as,lineNum);
}
} catch (FileNotFoundException e) {
System.out.print("文件没有找到,请输入正确的文件路径");
} catch (IOException e) {
}
}
/**
* 自动换行读取
* @param as 读取的字符
* @param lineNum 每行多少个字
*/
private static void readByLineNumber(String as,int lineNum){
for (int i = 0; i < as.length();) {
line++;
if(as.length()>=i+lineNum){
System.out.println(as.substring(i, i + lineNum)+ "----------" + line);
as=as.substring(i+lineNum,as.length());
}else{
System.out.println(as+ "----------" + line);
return;
}
}
}
}