我想讀取文本文件的前3個句子並將其顯示爲TextView。我的意圖是在完全停止後分割每個句子並將每個句子發送到數組列表。然後顯示存儲在數組列表中的前三個句子。這是我必須通過文本循環並獲得前3行的代碼。閱讀文本文件的前3個句子並在屏幕上顯示
reader = new BufferedReader(
new InputStreamReader(getAssets().open("inputNews.txt")));
String line;
List<String> sentence = new ArrayList<String>();
while ((line = reader.readLine()) != null) {
sentence.add(line.split("[\\.\\?\\!][\\r\\n\\t ]+")[0] + ".");
if(sentence.size() < 4){
text.append(sentence);
text.append('\n');
}
然後我輸出使用該信息,
TextView output= (TextView) findViewById(R.id.summtext);
output.setText((CharSequence) text);
然而,當我運行這個程序,它通過讀取該文件,並打印出這樣的文字,
[Sentence one..]
[Sentence one..Sentence two.]
[Sentence one..Sentence two. Sentence Three..]
我不不知道爲什麼它會產生雙重停頓(..)和[]。我的意圖是獲得這樣的結果,
Sentence one. Sentence two. Sentence three.
我該如何解決它?
感謝它的工作。最後在代碼中應該有一個額外的「)」。 – user5455438
對,編輯,很高興它幫助。 – Nanoc