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().endsWi th(".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();
}
}
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().endsWi
}
};
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
>>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]
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]
Antoni,
We're waiting for comment at https://www.experts-exchange.com/questions/21462925/FileFilter-compiler-error.html
We're waiting for comment at https://www.experts-exchange.com/questions/21462925/FileFilter-compiler-error.html
ASKER
Thanks