读取.txt文件中的特定列???我需要运行特定的列

问题描述 投票:0回答:1

文本文件内容如下:

**Name  class Section School**  
tin    10     a        ysr 
cane    9     a        cik
morj    8     b        vit
vel     7     d        klm
java split row text-files identity-column
1个回答
0
投票

此解决方案正在使用您提供的输入,但这是一个快捷解决方案。这个解决方案对您来说足够好,还是您想要一个更好的解决方案?

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;

public class FIrst {
      public static void main(String[] args)throws Exception 
      { 

      File file = new File("data.txt"); 

      BufferedReader br = new BufferedReader(new FileReader(file)); 

      String st; 

      String[] columnNames = null;
      if ((st = br.readLine()) == null) {
          System.out.println("did not find first line");
          return;
      }

      while ((st = br.readLine()) != null) 
        System.out.println(st.split(" ")[3]);
      } 
}
© www.soinside.com 2019 - 2024. All rights reserved.