public static List < String > formatKommaSeperatedFileToList ( final File input , final String encoding ) throws IOException { // The List where the data from every line from the File to put. final List < String > output = new ArrayList <> ( ) ; try ( BufferedReader reader = ( BufferedReader ) StreamExtensions . getReader ( input , encoding , false ) ) { // the line. String line = null ; // read all lines from the file do { line = reader . readLine ( ) ; // if null break the loop if ( line == null ) { break ; } // Split the line final String [ ] splittedData = line . split ( "," ) ; // Iterate throuh the array for ( final String element : splittedData ) { // add the line to the list output . add ( element . trim ( ) ) ; } } while ( true ) ; } // return the list with all lines from the file. return output ; }
Reads every line from the File splits the data through a comma and puts them to the List .