import java.io.*;
public class ReadFile {
public static void read(File f) throws IOException {
//String delimiters = ".";
FileReader fr = new FileReader(f);
BufferedReader br = new BufferedReader(fr);
String line;
//int numberOfLines = 0;
while ((line = br.readLine()) != null) {
String[] tokens = line.split("\\.", 2);
String p1 = tokens[0];
String p2 = tokens[1];
System.out.println(p1);
System.out.println(p2);
//numberOfLines++;
}
//System.out.println("Numebr of lines in file: " + numberOfLines);
br.close();
fr.close();
}
public static void main(String[] args) {
File f = new File("F:\\Dictionary.txt");
try {
read(f);
} catch (IOException ex) {
ex.printStackTrace();
}
}
}
私は辞書をテキストファイルとして使用していますが、辞書ファイルの行を読みたい私は "単語"とその "意味"を別の配列インデックスに格納できるように分割します。このString[] tokens = line.split("\\.", 2); to read and split at only the first "." (so that words proceeding after "." will be splitted!). I seem to having an error of ArrayIndexOutOfBound and I don't know why. I want
文字列p1 =トークン[0]。単語と `String p12 = tokens 1;を格納します。言葉の意味どうしたらいいですか? 辞書のリンク。ファイルを読み込み(FileReaderを使用)、Javaの2つの文字列に分割する