在Java中读取文件时忽略一行 [英] Ignore a line while reading a file in java

查看:68
本文介绍了在Java中读取文件时忽略一行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些代码可以从文件中读取行,我想识别行何时开始或fisrt字符(非空白)为'​​ * '并忽略它,因此在while语句添加类似

I have some code to read the lines from a file, I would like to recognize when the line starts or the fisrt character (not blank) is '*' and ignore it, so inside the while statement add something like

if(line[0]=='*') 
   ignore that line

我有类似的东西:

   input = new BufferedReader(new FileReader(new File(finaName)));
    String line = null;
    while ((line = input.readLine()) != null) {
    String[] words = line.split(" "); 
        .... 
    }

如何完成代码?

推荐答案

input = new BufferedReader(new FileReader(new File(finaName)));
String line = null;
while ((line = input.readLine()) != null) {
  if(line.trim().indexOf('*') == 0)
    continue;
  String[] words = line.split(" "); 
    .... 
}

这篇关于在Java中读取文件时忽略一行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆