これはばかげた質問かもしれませんが、StreamTokenizer が入力ストリームを区切る方法を認識するのに苦労しています。スペースとネクストラインで区切られていますか?wordChars() の使用についても混乱しています。例えば:
public static int getSet(String workingDirectory, String filename, List<String> set) {
int cardinality = 0;
File file = new File(workingDirectory,filename);
try {
BufferedReader in = new BufferedReader(new FileReader(file));
StreamTokenizer text = new StreamTokenizer(in);
text.wordChars('_','_');
text.nextToken();
while (text.ttype != StreamTokenizer.TT_EOF) {
set.add(text.sval);
cardinality++;
// System.out.println(cardinality + " " + text.sval);
text.nextToken();
}
in.close();
} catch (IOException ex) {
ex.printStackTrace();
}
return cardinality;
}
テキスト ファイルに A_B_C D_E_F という文字列が含まれている場合。
text.wordChars('_','_') は、アンダースコアのみが有効な単語と見なされることを意味しますか?
この場合、トークンは何になりますか?
どうもありがとうございました。