简体   繁体   中英

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 , . 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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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