简体   繁体   English

如何通过(选项卡)读取 csv 文件并通过 java 将文件存储到 arraylist

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

I'm a beginner at java programming.我是 java 编程的初学者。 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.我需要帮助如何通过(选项卡)读取 csv 文件并将文件存储到 ArrayList 以及如何从文件中读取特定单元格。 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'.制表符分隔符是 '\t' 而不是 '\tab'。 if you need to read specific cell in an excel you need to use a library like apache poi如果您需要读取 excel 中的特定单元格,您需要使用像 apache poi 这样的库

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

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