Java_tokenizer のバックアップの現在との差分(No.1) - アールメカブ

アールメカブ


Java_tokenizer のバックアップの現在との差分(No.1)


  • 追加された行はこの色です。
  • 削除された行はこの色です。
[[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) {
   public static void main(String[] args) {
		// TODO Auto-generated method stub
		long start = System.currentTimeMillis();
	    
	long start = System.currentTimeMillis();
 
	try {
		FileReader fr = new FileReader("dickens.txt");
		BufferedReader br = new BufferedReader(fr);
		String line;
		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();
			while((line = br.readLine()) != null){
				//System.out.println(line);
				st = new StringTokenizer(line);
				while (st.hasMoreTokens()) {
					vec.addElement(st.nextToken());
			     }
			}

		} catch (FileNotFoundException e) {
		} catch (IOException 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) + " ミリ秒");
		} 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) + " ミリ秒");
     }
 }