Hello everyone, I am trying to write to a file what I am currently displaying on the console.
I have a bit of code that works fine by creating a list of files based on it's file extention and it then displays it using println:
What I want it to write that list to a file, rather than display on console.
This is what I am doing.
public class ShowFiles {
public static void main(String[] args) throws FileNotFoundException {
List<File> listFiles = ScanFiles.getFileList();
for (File aList : listFiles) {
if (aList.isFile() && aList.getName().toLowerCase().endsWith(".txt")
|| aList.getName().toLowerCase().endsWith(".java"))
System.out.println(aList);
}
}
}
What do I need to do or how do I need to do it that instead of:
System.out.println(aList);
I get it to write to a File, I already found examples and documents but they always use txt examples and it does not work as I can not do
output.write(text);
unless it is plain text I declared.
Many Thanks in advance.