public static void main(String[] args) throws IOException {
FileReader a = new FileReader(new File("C:\\Users\\IBM_ADMIN\\Desktop\\SAM_PUBLIC_MONTHLY_20150802\\a.txt")); // new file
FileReader b = new FileReader(new File("C:\\Users\\IBM_ADMIN\\Desktop\\SAM_PUBLIC_MONTHLY_20150802\\b.txt")); // new file
@SuppressWarnings("resource")
BufferedReader file1 =new BufferedReader(a); //new
@SuppressWarnings("resource")
BufferedReader file2 =new BufferedReader(b); //old
PrintWriter Uniquefile = new PrintWriter (new File("C:\\Users\\IBM_ADMIN\\Desktop\\SAM_PUBLIC_MONTHLY_20150802\\samnew.dat"));
List<String> list= new ArrayList<String>();
while(file1.readLine()!=null)
{
String str=file1.toString();
list.add(str);
while(file2.readLine()!=null)
{
String str1=file2.toString();
if(list.contains(str1))
{
list.remove(str);
}
}
}
Iterator<String> it=list.iterator();
while(it.hasNext())
{
String str2=it.toString();
Uniquefile.write(str2);
}
}
I am Iterating 2 files to remove any common string lines and separate out unique strings.
Ex: File 1 .txt has string lines "1 2 3" and file 2.txt has "2 3" , I want to print "1" in File 3.txt.
Hope my question is clear. Would be great if someone can correct my code shown below. Thanks