자바 텍스트 파싱에 익숙하지 않고 각 행의 형식을 알 때 파일을 구문 분석하는 가장 좋은 방법이 무엇인지 궁금합니다.Java에서 C 스타일로 구문 분석 하시겠습니까?
나는 각 줄의 형식은 다음 파일이 있습니다
지능, 문자열, 두 번, 문자열, 두 번, 문자열, 두 번, 두 번 문자열, 문자열, 더블
참고 어떻게 문자열 , 쉼표로 구분 된 쌍의 쌍으로 행동하고 각 쌍은 세미콜론으로 구분됩니다.
몇 가지 예 :
1;art,0.1;computer,0.5;programming,0.6;java,0.7;unix,0.3 2;291,0.8;database,0.6;computer,0.2;java,0.9;undegraduate,0.7 3;coffee,0.5;colombia,0.2;java,0.1;export,0.4;import,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());
}
}
감사합니다 :)