`

软件包 java.io_Sort

阅读更多
package com.io;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class JavaIoSortUtils {
	public static void main(String[] args) throws IOException {
		String pathname = "D:\\Temp\\javaIo.txt";
		
		BufferedReader br = new BufferedReader(new FileReader(new File(pathname)));
		String str ;
		
		List<String> reader = new ArrayList<String>();
		List<String> writer = new ArrayList<String>();
		List<String> inputStream = new ArrayList<String>();
		List<String> outputStream = new ArrayList<String>();
		
		List<String> other = new ArrayList<String>();
		
		List<String> all = new ArrayList<String>();
		
		while ((str = br.readLine()) != null) {
			if(str == null || "".equalsIgnoreCase(str.trim())){continue;}
			str = str.trim();
			
			if(str.endsWith("Reader")){
				reader.add(str);
			}else if(str.endsWith("Writer")){
				writer.add(str);
			}else if(str.endsWith("InputStream")){
				inputStream.add(str);
			}else if(str.endsWith("OutputStream")){
				outputStream.add(str);
			}else{
				other.add(str);
//				System.out.print(str + "\r");
			}
		}
		
		all.addAll(reader);
		all.addAll(writer);
		all.addAll(inputStream);
		all.addAll(outputStream);
		all.addAll(other);
		
		Collections.sort(reader);
		Collections.sort(writer);
		Collections.sort(inputStream);
		Collections.sort(outputStream);
		Collections.sort(other);
		
		System.out.println(reader);
		System.out.println(reader.size());
		
		System.out.println(writer);
		System.out.println(writer.size());
		
		System.out.println(inputStream);
		System.out.println(inputStream.size());
		
		System.out.println(outputStream);
		System.out.println(outputStream.size());
		
		System.out.println(other);
		System.out.println(other.size());
		
//		System.out.println(all);
		System.out.println(all.size());
		
		br.close();
	}
}

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics