自己定义一个Comparator,然后用段洞Arrays.sort(file,new FileComparator())。
FileComparator可以按下面的来定义:
class FileComparator implements Comparator<File> {@Override
public int compare(File f1, File f2) {
握困枯 String 尺辩s1=f1.getName().substring(3)
String s2=f2.getName().substring(3)
int i1=Integer.parseInt(s1)
int i2=Integer.parseInt(s2)
return i1-i2
}
}
List<FileInfo>list=new List<FileInfo>(new DirectoryInfo("路径耐迅"升核).GetFiles())list.Sort()
这样行不?
那就用函数来实现排序吧
private void Form1_Load(object sender, EventArgs e)
{
List<FileInfo>list = new List<昌笑此FileInfo>(new DirectoryInfo(@"路径").GetFiles())
Comparison<FileInfo>com = new Comparison<FileInfo>(Compare)
list.Sort(com)
List<String>listS = new List<string>()
foreach (FileInfo info in list)
{
listS.Add(info.FullName)
}
richTextBox1.Lines = listS.ToArray()
}
private int Compare(FileInfo info1, FileInfo info2)
{
int result
CaseInsensitiveComparer ObjectCompare = new CaseInsensitiveComparer()
result = ObjectCompare.Compare(info1.FullName, info2.FullName)
return result
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)