Converting CSV File to Java - Copied in Backwards

后端 未结 1 1620
我寻月下人不归
我寻月下人不归 2021-01-25 22:11

I previously asked a question about converting a CSV file to 2D array in java. I completely rewrote my code and it is almost reworking. The only problem I am having now is that

相关标签:
1条回答
  • 2021-01-25 22:31

    so you want to read a CSV file in java , then you might wanna use OPEN CSV

    import java.io.FileNotFoundException;
    import java.io.FileReader;
    import java.io.IOException;
    
    import au.com.bytecode.opencsv.CSVReader;
    
    public class CsvFileReader {
        public static void main(String[] args) {
    
            try {
                System.out.println("\n**** readLineByLineExample ****");
                String csvFilename = "C:/Users/hussain.a/Desktop/sample.csv";
                CSVReader csvReader = new CSVReader(new FileReader(csvFilename));
                String[] col = null;
                while ((col = csvReader.readNext()) != null) 
                {
                    System.out.println(col[0] );
                    //System.out.println(col[0]);
                }
                csvReader.close();
            }
            catch(ArrayIndexOutOfBoundsException ae)
            {
                System.out.println(ae+" : error here");
            }catch (FileNotFoundException e) 
            {
                System.out.println("asd");
                e.printStackTrace();
            } catch (IOException e) {
                System.out.println("");
                e.printStackTrace();
            }
        }
    }
    

    and you can get the related jar file from here

    0 讨论(0)
提交回复
热议问题