Note that there are some explanatory texts on larger screens.

plurals
  1. POTrouble with array-list when storing the file data in the array-list
    text
    copied!<p>I am trying to find the difference between two text files and trying to write the diffrence in the third file !!! I am quite successful to do that but my file is too big it has almost 200000 lines and when I am storing it in to an arrylist it only stores the data till line no 6482 .I dont understand why it is happening. Can anyone please help me with that ? Here is my code </p> <pre><code> import java.io.*; import java.io.*; import java.util.ArrayList; import java.util.List; import java.util.Scanner; public class SearchThe { public static void main(String args[]) { try { // Open the file c:\test.txt as a buffered reader Scanner s = new Scanner(new File("D://abc.txt")); Scanner s2 = new Scanner(new File("D://xyz.txt")); // Scanner s = new Scanner(new File("D://file1.txt")); // Scanner s2 = new Scanner(new File("D://file2.txt")); ArrayList&lt;String&gt; file1_list = new ArrayList() ; ArrayList&lt;String&gt; file2_list = new ArrayList(); // file1_list.ensureCapacity(193225); // file2_list.ensureCapacity(193225); while (s.hasNext()) { file1_list.add(s.next()); } s.close(); while (s2.hasNext()) { file2_list.add(s2.next()); } s2.close(); FileWriter stream = new FileWriter("D://file1_copy.csv"); BufferedWriter abc = new BufferedWriter(stream); for(int i=0;i&lt;file1_list.size();i++) { System.out.println("File 1 data" +file1_list.get(i)); abc.write(file1_list.get(i));abc.newLine(); } abc.close(); // // Start a line count and declare a string to hold our current int linecount = 0; String line; // Let the user know what we are searching for // for(int i=0;i&lt;file1_list.size();i++) // { // Loop through each line, stashing the line into our line FileWriter fstream = new FileWriter("D://result.txt"); BufferedWriter out = new BufferedWriter(fstream); for(int j =0;j&lt;file1_list.size();j++) { System.out.println("\n\nSearching for " + file1_list.get(j) + " in file 1..."); if(file2_list.contains(file1_list.get(j))) { System.out.println(file1_list.get(j) +" found in a file 2"); } else { System.out.println(file1_list.get(j) +" not found in a file 1 "); out.write(file1_list.get(j));out.newLine(); } } out.close(); } catch (IOException e) { System.out.println("IO Error Occurred: " + e.toString()); } } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload