res/raw/textに置かれたテキストファイルから読みたい 読み込みに成功しましたが、出力のすべての行の後に奇妙な文字がありますこのようなもの "[]"。 この文字は、ソースファイル(テキスト)に新しい行がある出力のすべての行の最後にあります。 はどのようにテキストファイルを作成しました。..すべての行からこの文字を削除する方法Androidのテキストファイル(rawディレクトリ)が正しく読み取られない
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