java读取txt从第四行开始每行为一个对象存放进list 10
2017-05-22
展开全部
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();
}
}
}
}
// 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();
}
}
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询