I need to form an ArrayList for the "normal" array file [].
File[] fSorted = (File[]) x.toArray();
Error: Cast Exception
Exception in thread "Thread-5" java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to [Ljava.io.File;
How can I return the list x to the [] -List file?
-
My function:
private File[] sortFiles(File[] files){; ArrayList<String> allFiles = new ArrayList<String>() ; for (int index = 0; index < files.length; index++) { File afile = new File(files[index].toString()); allFiles.add(afile.getPath().toString()); } java.util.Collections.sort(allFiles); ArrayList<File> x = new ArrayList<File>(); for(int i = 0; i< allFiles.size(); ++i){ x.add(new File(allFiles.get(i))); } File[] fSorted = (File[]) x.toArray(); return fSorted; }
source share