Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

csv compare java

//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 :: java.lang.NoClassDefFoundError 
Java :: how use a if in java 
Java :: pythagoras method in java 
Java :: java string equals null 
Java :: Java Access ConcurrentHashMap Elements 
Java :: HashMap to store key and value pair. 
Java :: Android Gradle plugin requires Java 11 to run. You are currently using Java 1.8 
Java :: creating jdbc connection in java using service name oracle 
Java :: java enum to string 
Java :: spring-boot-maven-plugin not found 
Java :: java abstract modifier 
Java :: java create array with values 
Java :: search 
Java :: 2048 java code 
Java :: java list of a class has a string that is equal to 
Java :: java developer interview questions 
Java :: java timeout exception 
Java :: random suffling java 
Java :: precision java 
Java :: stringbuilder in java 
Java :: Java Create a Scanner Object in Java 
Java :: Java Creating a HashSet 
Java :: how to create a new imageview in android java 
Java :: merge sort recursion java 
Java :: map.put in java 
Java :: No enclosing instance of type Foo is accessible. Must qualify the allocation with an enclosing instance of type Foo (e.g. x.new A() where x is an instance of Foo 
Java :: java class 
Java :: javafx 
Java :: jdsu software download 
Java :: java cant use string functions after changing an integer into string 
ADD CONTENT
Topic
Content
Source link
Name
3+5 =