简体   繁体   English

来自文本文件的Android 2d数组

[英]Android 2d array from text file

So what I'm trying to do is I have a text file that has 5580 lines and then has 9 columns separated by a , . 所以我想做的是有一个文本文件,该文件有5580行,然后有9列,中间用,分隔。 I'm trying to have the user input an entry that will be in the first column and I need to search for that entry and pull the rest of the information. 我正在尝试让用户输入将在第一列中输入的条目,我需要搜索该条目并提取其余信息。 Java is new to me (I'm starting to miss fortran or python) any help? Java对我来说是新手(我开始错过fortran或python)有什么帮助吗?

Learn about input streams and readers. 了解输入流和读者。 Here is some code sample that can be used by you to start. 这是您可以用来启动的一些代码示例。

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...
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM