Comparing two text files in random order with Java
<p>I am trying to compare two text files that are randomized and print out the lines that match in both of the files.
File 1:</p>

<pre><code>Student1
Student2
Student3
Student4
</code></pre>

<p>File 2:</p>

<pre><code>Student6
Student1
Student2
</code></pre>

<p>I want the output as </p>

<pre><code>Student1
Student2
</code></pre>

<p>My code is below.</p>

<pre><code>public static void main(String[] args) throws IOException {

     String first = "file1.txt";
     String second = "file2.txt";
     BufferedReader fBr = new BufferedReader(new FileReader(first));
     BufferedReader sBr = new BufferedReader(new FileReader(second));   




     PrintWriter writer = new PrintWriter("test.txt", "UTF-8");  
     while ((first = fBr.readLine()) != null) {
         String partOne1 = fBr.readLine();
         String partTwo1 = sBr.readLine();
         while ((second = sBr.readLine()) != null) {
                System.out.println(first);
                writer.println(first);  
                break;                   

         }
     }


     writer.close();
     fBr.close();
     sBr.close(); 
</code></pre>