【发布时间】:2012-01-15 08:34:56
【问题描述】:
我想从 res/raw/text 中的文本文件中读取 我阅读成功,但在我的输出中的每一行之后都有一个奇怪的字符,比如“[]”。 这个字符位于输出中每一行的末尾,在我的源文件(文本)中有新行的地方。 不知道如何从每一行中删除这个字符..
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();
}
}
【问题讨论】: