이 컴퓨터 의 모든 접미사 파일 이름 가 져 오기 --- 자바

1804 단어
package com.satan.suffix;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;

public class CountSuffix
{
   private static Set<String> suffixSet = new HashSet<String>();
   private static String file = "F:\\1.txt";
   public static void main(String[] args) throws IOException
   {
       long start,end;

       start = System.currentTimeMillis();
       countSuffix(File.listRoots());
       System.out.println("   " + suffixSet.size()+ "    ");
       end = System.currentTimeMillis();
       System.out.println("Time use: " + (end-start) + "ms");
       
       
       FileOutputStream fos = new FileOutputStream(file);
       OutputStreamWriter osr = new OutputStreamWriter(fos);
       BufferedWriter bw = new BufferedWriter(osr);

       Iterator<String> iter = suffixSet.iterator();
       while(iter.hasNext())
       {
           bw.write(iter.next()+"\r
"); } bw.close(); } private static void countSuffix(File[] files) throws IOException { if(files != null) { for (File file : files) { if(file != null) { if(file.isFile() && file.getName().contains(".")) { String fileName = file.getName(); String[] word = fileName.split("\\.");//split suffixSet.add(word[word.length-1]); } countSuffix(file.listFiles()); } } } } }

좋은 웹페이지 즐겨찾기