事情很简单,但不能按原样运作.
我有一个文本文件作为原始资源添加.文本文件包含如下文本:
b)如果适用法律要求对软件提供任何担保,则所有此类担保的有效期限为交付日期后的第九十(90)天.
(c)虚拟定向,其经销商,经销商,代理商或雇员提供的任何口头或书面信息或建议均不构成保证或以任何方式增加此处提供的任何保证的范围.
(d)(仅限美国)有些州不允许排除默示担保,因此上述排除条款可能不适用于您.本担保赋予您特定的法律权利,您可能还拥有其他法律权利,这些权利因国家/地区而异.
在我的屏幕上,我有这样的布局:
<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>
Run Code Online (Sandbox Code Playgroud)
读取原始资源的代码是:
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();
}
Run Code Online (Sandbox Code Playgroud)
文本得到了显示,但在每一行后我得到一个奇怪的字符[]如何删除该字符?我认为这是新线.
工作解决方案
public static …Run Code Online (Sandbox Code Playgroud)