---
# System prepended metadata

title: 12/18Lab只印出檔名不要印出路徑
tags: [JAVA]

---

# 12/18Lab只印出檔名不要印出路徑
###### tags: `JAVA`
	public static void main(String[] args) {
		File file = new File("C:\\Program Files\\JDK8\\include");
		File[]files = file.listFiles();
		Set<File> set = new TreeSet<>(new Comparator() {

			@Override
			public int compare(Object o1, Object o2) {
				File f1=(File)o1;
				File f2=(File)o2;
				if(f1.length()<f2.length())
				{
					return -1;
				}else if(f1.length()>f2.length())
				{
					return 1;
				}else 
				{
					return 0;
				}		
			}		
		});		
		for(File item:files)
		{
			if(!item.isDirectory())
			{
				set.add(item);
			}
			
		}
		for(File item:set)
		{
			System.out.println(item.getName());
		}

	}