我想從放在res/raw /文本中的文本文件中讀取 我已成功讀取,但在輸出中的每一行後都有一個奇怪的字符像這樣的「[]」。 而且這個字符在輸出中每一行的末尾,在我的源文件(文本)中有新行。 不知道如何從每一行中刪除這個角色..未正確讀取Android文本文件(在原始目錄中)
public class HelpActivity extends Activity{
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.help);
TextView textview = (TextView)findViewById(R.id.TextView_HelpText);
textview.setText(readTxt());
}
private String readTxt() {
InputStream is = getResources().openRawResource(R.raw.text);
ByteArrayOutputStream byteArray = new ByteArrayOutputStream();
int i;
try
{
i = is.read();
while (i != -1)
{
byteArray.write(i);
i = is.read();
}
is.close();
}
catch (IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
return byteArray.toString();
}
}
感謝stevehb像這樣
部分借用..我已經從你的答案:)解決我的問題 – Itian