如何从文件中读取和分割数据,但在Java中也忽略一些数据

如何从文件中读取和分割数据,但在Java中也忽略一些数据,java,bufferedreader,Java,Bufferedreader,我不知道如何解释,但我有这样的数据 1 John US 38 24 090921 2 Dave UK 29 12 043721 3 James US 31 87 823874 数据由选项卡分隔,我只想这样读取我的数据 1 John US 38 2 Dave UK 29 3 James US 31 我怎样才能在Java中做到这一点?你能给我看看代码的样本吗?谢谢。我想这对你的情况会有帮助。 BufferedRead

我不知道如何解释,但我有这样的数据

1   John    US  38  24  090921
2   Dave    UK  29  12  043721
3   James   US  31  87  823874
数据由
选项卡
分隔,我只想这样读取我的数据

1   John    US  38
2   Dave    UK  29
3   James   US  31

我怎样才能在Java中做到这一点?你能给我看看代码的样本吗?谢谢。

我想这对你的情况会有帮助。

BufferedReader in = null;
try {
    in = new BufferedReader(new FileReader("filename"));
    String read = null;
    while ((read = in.readLine()) != null) {
        String[] splited = read.split("\\s+");
        for (String part : splited) {
            System.out.println(part); // to read the data is inputted correctly or not
        }
    }
} catch (IOException e) {
    System.out.println("There was a problem: " + e);
    e.printStackTrace();
} finally {
    try {
        in.close();
    } catch (Exception e) {
    }
}

逐行阅读,逐行拆分,取前4个值。