java读取隔行文件的方法

public static void main(String[] args) {
try {
BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(new File("input.dat")),
"UTF-8"));
String lineTxt = null;
int a = 0;
ArrayList 奇数行 = new ArrayList<>();
ArrayList 偶数行 = new ArrayList<>();
while ((lineTxt = br.readLine()) != null) {
a++;
if(a%2==0){
偶数行.add(lineTxt);
}else {
奇数行.add(lineTxt);
}
}
br.close();
} catch (Exception e) {
System.err.println("read errors :" + e);
}
}

猜你喜欢

转载自blog.csdn.net/always_myhometown/article/details/78468583
今日推荐