Android讀取文本原始資源文件事情很簡單,但不能按原樣運作。我有一個文本文件作為原始資源添加。文本文件包含如下文本:b)如果適用法律要求對軟件提供任何擔保,則所有此類擔保的有效期限為交付日期后的第九十(90)天。(c)虛擬定向,其經(jīng)銷商,經(jīng)銷商,代理商或雇員提供的任何口頭或書面信息或建議均不構成保證或以任何方式增加此處提供的任何保證的范圍。(d)(僅限美國)某些州不允許排除默示擔保,因此上述排除條款可能不適用于您。本擔保賦予您特定的法律權利,您可能還擁有其他法律權利,這些權利因國家/地區(qū)而異。在我的屏幕上,我有這樣的布局:<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_weight="1.0"
android:layout_below="@+id/logoLayout"
android:background="@drawable/list_background">
<ScrollView android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView android:id="@+id/txtRawResource"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="3dip"/>
</ScrollView>
</LinearLayout>讀取原始資源的代碼是:TextView txtRawResource= (TextView)findViewById(R.id.txtRawResource);txtDisclaimer.setText(Utils.readRawTextFile(ctx, R.raw.rawtextsample);public static String readRawTextFile(Context ctx, int resId){
InputStream inputStream = ctx.getResources().openRawResource(resId);
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
int i;
try {
i = inputStream.read();
while (i != -1)
{
byteArrayOutputStream.write(i);
i = inputStream.read();
}
inputStream.close();
} catch (IOException e) {
return null;
}
return byteArrayOutputStream.toString();}文本得到了顯示,但在每一行后我得到一個奇怪的字符[]如何刪除該字符?我認為這是新線。
3 回答

蕭十郎
TA貢獻1815條經(jīng)驗 獲得超13個贊
如果使用基于字符的BufferedReader而不是基于字節(jié)的InputStream,該怎么辦?
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));String line = reader.readLine();while (line != null) { ... }
不要忘記readLine()
跳過新線!
- 3 回答
- 0 關注
- 498 瀏覽
添加回答
舉報
0/150
提交
取消