I created a JList
that contains a list of files that are in a directory.
Here is the JList
.
JList MList;
String ListData[]
// Creat
Just edit your code like this,
public ArrayList ReadDirectory() {
String path = "C://Documents and Settings/myfileTxt";
ArrayList files = new ArrayList();
File folder = new File(path);
File[] listOfFiles = folder.listFiles();
for (int i = 0; i < listOfFiles.length; i++) {
if (listOfFiles[i].isFile()) {
files.add(listOfFiles[i].getName());
if (files.endsWith(".txt") || files.endsWith(".TXT")) {
System.out.println(files);
}
}
}
return files;
}
Which will return ArrayList object and then you can convert that ArrayList object to a normal array.
Something like this, Lets say your variable name is,
ArrayList listData = new ArrayList();
Just do this to convert it into normal array,
listData.toArray();