我正在尝试将文本文件读入字符串变量。文本文件有多行。打印字符串以测试“读入”代码后,每个字符之间都有一个额外的空格。当我使用字符串生成字符二元组时,空格使示例文本无用。代码是
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());
}
我会很感激任何建议。
谢谢。