私はJavaテキストの解析に不慣れで、各行の形式がわかっている場合にファイルを解析するための最良の方法は何でしょうか。
各行に次の形式のファイルがあります。
Int; String、double; String、double; String、double; String、double; String、double
String、doubleがコンマで区切られたペアとして機能し、各ペアがセミコロンで区切られていることに注意してください。
いくつかの例:
1; art、0.1; computer、0.5; Programming、0.6; java、0.7; unix、0.3 2; 291,0.8;データベース、0.6;コンピューター、0.2; java、0.9;学部生、0.7 3;コーヒー、0.5;コロンビア、0.2; java、0.1;エクスポート、0.4;インポート、0.5
次のコードを使用して各行を読み取ります。
public static void main(String args[]) {
try {
// Open the file that is the first
// command line parameter
FileInputStream fstream = new FileInputStream("textfile.txt");
// Get the object of DataInputStream
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String strLine;
// Read File Line By Line
while ((strLine = br.readLine()) != null) {
// Print the content on the console
System.out.println(strLine);
}
// Close the input stream
in.close();
} catch (Exception e) {// Catch exception if any
System.err.println("Error: " + e.getMessage());
}
}
前もって感謝します :)