Converting a println out in to a method
I have a class that returns a result to command line using println (list);
THIS IS THE RESULT WHEN I RUN THE FIRST CLASS
C:\>java -cp Details.jar packages.ListFiles
C:\temp\bkdb.txt
C:\temp\nbu6.5.6\BitmapImage.bmp
C:\temp\nbu6.5.6\Something.txt
C:\temp\New Bitmap Image.bmp
C:\temp\New Text Document.txt
Code:
public static void main(String[] args) throws FileNotFoundException {
// USING java.io.File
File folder = new File("C:/temp");
// USING java.util.List
List<File> contents = ListFiles1.getFileListing(folder);
// PRINT OUT THE LIST OF FILES
for (File list : contents) {
if (list.isFile() && list.getName().toLowerCase().endsWith(".txt")
|| list.getName().toLowerCase().endsWith(".bmp")
|| list.getName().toLowerCase().endsWith(".doc")
)
System.out.println(list);
}
}
So I have aquestion then, can I take this code I have with a for loop on specific files and convert that to a method so that the second class can access it?
Many Thanks