मुझे एक "सामान्य" ऐरे फ़ाइल [] में एक ऐरेलिस्ट बनाना है।ऐरे फ़ाइल <File> ऐरे फ़ाइल में []
File[] fSorted = (File[]) x.toArray();
त्रुटि: Cast Exception
Exception in thread "Thread-5" java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to [Ljava.io.File;
मैं कैसे फ़ाइल [] -List के रूप में सूची x
लौट सकते हैं?
-
मेरे समारोह:
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;
}
के संभावित डुप्लिकेट [कन्वर्ट ArrayList स्ट्रिंग \ [\] के लिए] (http://stackoverflow.com/प्रश्न/5374311/कन्वर्ट-सरणीसूचीस्ट्रिंग-टू-स्ट्रिंग) –
Eric
[जावा में सरणी में कनवर्ट सूची] के संभावित डुप्लिकेट (http://stackoverflow.com/questions/9572795/convert-list-to-array-in-java) –