Java_tokenizer の変更点 - アールメカブ

アールメカブ


Java_tokenizer の変更点


[[Programming]]

* Javaでテキストをトークンに区切ってベクトルオブジェクトに入れる [#mbfb4adb]
 import java.io.BufferedReader;
 import java.io.FileNotFoundException;
 import java.io.FileReader;
 import java.io.IOException;
 import java.util.StringTokenizer;
 import java.util.Vector;
 
 public class StrToken {
	/**
	 * @param args
	 */
	static Vector vec = new Vector();
	static StringTokenizer st;
	
   public static void main(String[] args) {
		// TODO Auto-generated method stub
	long start = System.currentTimeMillis();
 
	try {
		FileReader fr = new FileReader("dickens.txt");
		BufferedReader br = new BufferedReader(fr);
		String line;
		try {
			while((line = br.readLine()) != null){
				//System.out.println(line);
				st = new StringTokenizer(line);
				while (st.hasMoreTokens()) {
					vec.addElement(st.nextToken());
			     }
			}
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		} catch (FileNotFoundException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
	long stop = System.currentTimeMillis();
	System.out.println("token size = " + vec.size());
	System.out.println("run time = " 
                       +  (stop - start) + " ミリ秒");
     }

 }