텍스트 파일을 String 변수로 읽으려고합니다. 텍스트 파일에는 여러 줄이 있습니다. 문자열을 인쇄하여 "read-in"코드를 테스트하면 모든 문자 사이에 공백이 추가됩니다. 문자 bigram을 생성하기 위해 String을 사용하기 때문에 공백으로 인해 샘플 텍스트가 쓸모 없게됩니다. 코드는FileInputStream을 사용하여 텍스트 파일을 String으로 읽는 문자열의 추가 공백
try {
FileInputStream fstream = new FileInputStream(textfile);
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
//Read corpus file line-by-line, concatenating each line to the String "corpus"
while ((strLine = br.readLine()) != null) {
corpus = (corpus.concat(strLine));
}
in.close(); //Close the input stream
}
catch (Exception e) { //Catch exception if any
System.err.println("Error test check: " + e.getMessage());
}
어떤 조언을 해주셔서 감사합니다.
감사합니다.