Writing Inside a text file using Scanner Class
<p>I have Come across so many programmes of how to read a text file using <code>Scanner</code> in Java. Following is some dummy code of Reading a text file in Java using <code>Scanner</code>:</p>

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

    File file = new File("10_Random");

    try {

        Scanner sc = new Scanner(file);

        while (sc.hasNextLine()) {
            int i = sc.nextInt();
            System.out.println(i);
        }
        sc.close();
    } 
    catch (FileNotFoundException e) {
        e.printStackTrace();
    }
 }
</code></pre>

<p>But, please anyone help me in "Writing" some text (i.e. String or Integer type text) inside a <code>.txt</code> file using <code>Scanner</code> in java. I don't know how to write that code.</p>