Link to home
Start Free TrialLog in
Avatar of AntoniRyszard
AntoniRyszard

asked on

FilenameFilter() question?

Hello,

Could any advise, in this example if I wanted store the wav file names in the array wavList, but add them to the string[] so the wav names start at position 1.

Would I need to copy wav names into the existing string[] and then copy them in a for loop into another string[] starting at 1?

Thanks

import java.io.*;
public class WavFiles {

     String [] wavList = null;
     public WavFiles ()
     {
          File dir = new File (".");
          FilenameFilter filter = new FilenameFilter ()
          {
               public boolean accept(File dir, String name) {
                    return (name.toLowerCase().endsWith(".wav"));
               }
               
          };
          wavList = dir.list(filter);
          for (int i = 0; i < wavList.length; i++)
               System.out.println (wavList[i] + "\n");
     }
     public static void main(String[] args)
     {
          WavFiles wav = new WavFiles();
         
     }
}
ASKER CERTIFIED SOLUTION
Avatar of StillUnAware
StillUnAware
Flag of Lithuania image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of AntoniRyszard
AntoniRyszard

ASKER

So you think it would not be possible to remove the wavList = dir.list(filter); line and change this into a for loop. Which could start at position 1?

Thanks
Avatar of CEHJ
>>so the wav names start at position 1.

Why would you want to do that? If you want to identify them with a 1-based index you can do

String file = array[i - 1]