永发信息网

java读取txt从第四行开始每行为一个对象存放进list

答案:1  悬赏:0  手机版
解决时间 2021-03-20 20:04
  • 提问者网友:献世佛
  • 2021-03-19 20:42
java读取txt从第四行开始每行为一个对象存放进list
最佳答案
  • 五星知识达人网友:冷風如刀
  • 2021-03-19 22:16
public static void main(String[] args) {
// TODO Auto-generated method stub
File file = new File("C:/zc.txt");
BufferedReader reader = null;
String tempString = null;
int line =1;

try {
System.out.println("以行为单位读取文件内容,一次读一整行:");
reader = new BufferedReader(new FileReader(file));
while ((tempString = reader.readLine()) != null) {
if(line >= 4){//自己写进OBJECT存入LIST
}
line ++ ;
}
reader.close();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally{
if(reader != null){
try {
reader.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯