 <p>You second thread is not appending content to the file, which was written by first thread. Instead it is overwriting content written by first thread. </p> <p>So you are getting output only from second thread.</p> <p>Change your code </p> <p>from </p> <pre><code> FileWriter f = new FileWriter("C:\\Users\\Desktop\\sample.txt"); </code></pre> <p>to </p> <pre><code> FileWriter f = new FileWriter("C:\\Users\\Desktop\\sample.txt",true); </code></pre> <p>Refer to java documentation <a href="https://docs.oracle.com/javase/8/docs/api/java/io/FileWriter.html#FileWriter-java.io.File-boolean-" rel="nofollow">page</a> on <code>FileWriter</code></p> <pre><code>public FileWriter(File file, boolean append) throws IOException </code></pre> <blockquote> <p>Constructs a FileWriter object given a File object. If the second argument is true, then bytes will be written to the end of the file rather than the beginning.</p> </blockquote>