0

所以我想做的是我有一个文本文件,它有 5580 行,然后有 9 列,由 , 分隔。我试图让用户输入一个将在第一列中的条目,我需要搜索该条目并提取其余信息。Java对我来说是新手(我开始想念fortran或python)有什么帮助吗?

4

1 回答 1

1

了解输入流和阅读器。这是一些可供您开始使用的代码示例。

String token = // init it
BufferedReader reader = new BufferedReader(new InputStreamReader(new FileReader(thefileName)));

for (String line = reader.nextLine(); line !=null; line = reader.nextLine()) {
    String[] parts = line.split(",");
    if (token.equals(parts[0])) {
       // this is the line you are looking for...
    }
}
于 2013-05-05T21:20:34.830 回答