Posts

Showing posts from July, 2016

Compare Text in 2 files and write the difference in a new file

Here I am reading 2 files, first file data is added to list.second file data is added to another list.Then converting 2 list to 2 Hashset. Then i am removing 1st hashset from the 2nd one.In this process all the common string will get removed and the new Hashset will have the difference data. /**  * Getting 2 text files with single column data in each, need to find out the difference and write the difference between the 2 files to a new file.  */ public class CompareTwoFiles { public static List readcsv(String filename) { List l=new ArrayList(); String tempstr = ""; String dataStr = ""; int rownum = 0; try { BufferedReader br = new BufferedReader(new FileReader(filename)); try { String line = ""; while ((line = br.readLine()) != null) { l.add(line); // System.out.println(dataStr); } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace();