I created a JList that contains a list of files that are in a directory.
Here is the JList.
JList MList;
String ListData[]
// Creat
I don't quite understand what you're doing - it looks like you want to filter the content of the JList to be only files with the .txt extension. In that case, you're probably looking to implement a FilenameFilter that will cause list() to return a list of file names in a String[] that only matches what you specified.
For example,
public String[] ReadDirectory() {
String path = "C://Documents and Settings/myfileTxt";
String files = null;
File folder = new File(path);
FilenameFilter txtFilter = new TextFileFilter();
String[] listOfFiles = folder.listFiles(txtFilter);
return listOfFiles;
}
public class TextFileFilter extends FilenameFilter
{
public boolean accept(File dir, String name)
{
if(name != null && name.endsWith(".txt"))
{
return true;
}
return false;
}
}