Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

csv compare

//download csv reader maven dependency for this
public class ReadCSV {
    public List<Map<String, String>> read(String filename) throws CsvValidationException, IOException {

        CSVReader csvReader = new CSVReader(new FileReader(filename));

        String[] headerArray = csvReader.readNext();
        String[] lineInArray;

        List<Map<String, String>> listOfMaps = new ArrayList<Map<String, String>>();

        while ((lineInArray = csvReader.readNext()) != null) {
            HashMap<String, String> map = new HashMap<String, String>();

            for (int i = 0; i < lineInArray.length; i++) {
                map.put(headerArray[i], lineInArray[i]);
            }

            listOfMaps.add(map);
            //System.out.println(map);
        }

        return listOfMaps;

    }


    public static void main(String[] args) throws IOException, CsvException {
        
        //select relative path of csv
        
        String filename1 = "test1.csv";
        String filename2 = "test2.csv";
        

        ReadCSV readCSV = new ReadCSV();

        List<Map<String, String>> file1 = readCSV.read(filename1);
        List<Map<String, String>> file2 = readCSV.read(filename2);

        for (int i = 0; i < file1.size(); i++) {

            if (!file1.get(i).equals(file2.get(i))) {
                System.out.println("file1: " + file1.get(i));
                System.out.println("file2: " + file2.get(i));
                System.out.println("---------------------");
            }
        }


    }
}
Comment

PREVIOUS NEXT
Code Example
Java :: string to pojo java 
Java :: expression régulière téléphone java 
Java :: byte array in java 
Java :: java base64 decrypt script 
Java :: Java Create a ByteArrayInputStream 
Java :: generic method lambda java 
Java :: android send fragment context 
Java :: java long data type 
Java :: change fab image programatically 
Java :: hbox layout javafx 
Java :: copy text from header tag in javacript 
Java :: Java 8 merge 2 collections. 
Java :: fibonacci of 6 
Java :: java nested static class 
Java :: radiogroup get selected item android 
Java :: how to change fragment on button click navigation drawer 
Java :: fragment call activity 
Java :: arrays with for loops 
Java :: how to convert double to int in java 
Java :: java array slicing 
Java :: int conversion to float 
Java :: get string size on screen 
Java :: how to set the length to int array in java 
Java :: the java_home environment variable is not defined correctly on mac 
Java :: loop and save letters in a string java 
Java :: how to initialize a variable in java 
Java :: string cannot be resolved to a type eclipse 
Java :: Java Handlers(Appenders) 
Java :: java truncate bigdecimal 
Java :: No enclosing instance of type Main is accessible. Must qualify the allocation with an enclosing instance of type Main (e.g. x.new A() where x is an instance of Main). 
ADD CONTENT
Topic
Content
Source link
Name
4+1 =