How to save output to a txt file
<p>Quick Q</p>

<p>i have a loop that finds all the files in a directory, what i want to do is add a line of code into it that would write these results into a txt file, how would i best do this </p>

<p>current code :</p>

<pre><code>public String FilesInFolder() {
        // Will list all files in the directory, want to create a feature on the page that can display this to the user

        String path = NewDestination;
        System.out.println("Starting searching files in directory"); // making sure it is called
        String files;
        File folder = new File(path);
        File[] listOfFiles = folder.listFiles();

        for (int i = 0; i &lt; listOfFiles.length; i++) {

            if (listOfFiles[i].isFile()) {
                files = listOfFiles[i].getName();
                System.out.println(files);
            }
        }
        return "";
    }
</code></pre>
