Hello, I am new to this codding stuff and I am only doing it for fun (personal little project) and for learing as I am not programer in any language apart from knowledge in shell scripting :(

Anyway after a few weeks looking at examples and searching the net and putting piaces together I have managed to create a class that will all files in a directory based on specific file extentions in(netBeans), this is a snip of the end of the 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);
        }
}

THIS IS THE RESULT WHEN I RUN THE FIRST CLASS

C:\>java -cp Details.jar packages.ListFiles
C:\temp\file_one.txt
C:\temp\dir6.5.6\BitmapImage.bmp
C:\temp\dir6.5.6\Something.txt
C:\temp\New Bitmap Image.bmp
C:\temp\New Text Document.txt


Now I want to create a second class that will use the output of the first class (ListFiles) and write it into a txt file, the problem is I can not get the second class to read the output of the first class.

I know that first I need change it so that instead of pronting the files to the console, it builds a List of the file and returns it.

Here is the problem, I can't figure it out :(

And then my second chalenge will be to see if my second class will work.

Any help woould be greatly appreciated. :)

Many Thanks in advance.

First, instead of putting all of your work in the main method, move the logic to it's own public method. Then, instead of printing out the results, make this method return a List<String>.

Create a second class that calls that method, retrieving the list, and writing the contents to a separate file.

Make sense?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.