mport java.io.*;
import java.util.Scanner;
public class Arr {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new FileReader("C:\\Users\\DaluxC\\Desktop\\新建文件夹δ\\新建文本文档.txt"));
String row;
int startR = 0, startC = 0, endR = 0, endC = 0;
int cut = 0;
boolean flag = false;
Scanner sc = new Scanner(System.in);
System.out.println("请输入开始的行 starR:");
startR = sc.nextInt();
System.out.println("请输入开始的列 starC:");
startC = sc.nextInt();
System.out.println("请输入结束的行 endR:");
endR = sc.nextInt();
System.out.println("请输入结束的列 endC:");
endC = sc.nextInt();
if(startR > endR){
System.out.println("您不能将开始的行设置得比结束的行还大");
System.exit(-1);
}
//确定开始的点、并输出从开始的点到倒数第二行的所有文本
while((row = br.readLine()) != null && cut < endR-1){
cut++;
if(cut == startR){
if(startC>row.length()){
System.out.println("第"+startR+"行没有第"+startC+"列");
System.exit(-1);
}
row = row.subSequence(startC, row.length()).toString();
flag = true;
}else{
row = row.subSequence(0, row.length()).toString();
}
if(flag)
System.out.println(row);
}
//特殊情况:同行之内截取、所给的开始行不存在
if(!flag){
//同行之内截取
if(startR == endR && (row = br.readLine()) != null){
if(startC<endC) {
System.out.println(row.subSequence(startC, endC));
System.exit(0);
}
else{
System.out.println("您不能将开始的点设置得比结束的点还靠后");
System.exit(-1);
}
}else {
//所给的开始行不存在
System.out.println("没有第" + startR + "行");
System.exit(-1);
}
}
//读取并输出最后一行的文本
if(row != null) {
if(endC > row.length()){
System.out.println("第"+endR+"行没有第"+endC+"列");
System.out.println("本次输出到了第"+cut+"行");
System.exit(-1);
}
System.out.println(row.subSequence(0, endC));
}else {
System.out.println("没有第" + endR + "行");
System.out.println("本次输出到了第"+cut+"行");
}
}
}