【问题标题】:reading a specific column in .txt file ??? i need to run a specific column读取 .txt 文件中的特定列 ???我需要运行一个特定的列
【发布时间】:2020-07-30 16:43:13
【问题描述】:

文本文件内容如下:

**Name  class Section School**  
tin    10     a        ysr 
cane    9     a        cik
morj    8     b        vit
vel     7     d        klm

【问题讨论】:

  • 您可以选择通过外部工具将 txt 转换为 csv 吗?然后在java中读取csv...
  • 请以代码格式输入文本,以便于阅读。
  • 你可以按空格分割行,得到你想要的列。
  • 您可以使用正则表达式。你能举个例子吗?你需要匹配什么。
  • 你能提供我解决的代码吗???????

标签: java split row text-files identity-column


【解决方案1】:

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

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]);
      } 
}

【讨论】:

  • 嗨 CrazyArtist,这是一个快捷且有效的解决方案....您想要其他解决方案还是该解决方案适合您?
猜你喜欢
  • 1970-01-01
  • 2021-12-24
  • 1970-01-01
  • 2019-08-01
  • 2018-06-28
  • 2014-06-03
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多