简体   繁体   中英

how to read csv file by (tab) and store file to arraylist by java

I'm a beginner at java programming. I need help how to read a csv file by (tab) and store file to ArrayList and how to read a specific cell from the file. Here's my code:


    public static void main (String[] args){
           String file_Name = "info.txt";
               File file = new File(file_Name);
           try {

               Scanner inputStream = new Scanner(file);
                while (inputStream.hasNext()){
                    String data = inputStream.next();
                    String [] values;
                    String delimeter;
                   delimeter = "\tab";
                   values = data.split(delimeter);

                }
                inputStream.close();

           } catch (FileNotFoundException e) {
               e.printStackTrace();
           }

       }

text file
Sweater gold    55.5 
Jeans   silver  68.5  
Hat gold    20.0

The tab delimeter is '\t' not '\tab'. if you need to read specific cell in an excel you need to use a library like apache poi

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