android bytearrayoutputstream用法,在Android中使用ByteArrayOutputStream的瑞典字母问题

我正在使用ByteArrayOutputStream将文本从IputStream放入文本视图中。 这工作正常,但... 我来自瑞典,当我把一些文字与一些特殊的瑞典字母,它放?而不是实际的信件。否则,系统对此字母没有问题。 希望有人在那里可以给我一个关于怎么做的提示。在Android中使用ByteArrayOutputStream的瑞典字母问题

也许我应当出示代码:

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.main);

TextView helloTxt = (TextView)findViewById(R.id.hellotxt);

helloTxt.setText(readTxt());

}

private String readTxt(){

InputStream inputStream = getResources().openRawResource(R.raw.hello);

ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();

int i;

try {

i = inputStream.read();

while (i != -1)

{

byteArrayOutputStream.write(i);

i = inputStream.read();

}

inputStream.close();

} catch (IOException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

return byteArrayOutputStream.toString();

}

}

我还绑着这一点,从论坛(Selzier)得到它: 尼斯和平,但仍然没有瑞典语字母输出:

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.main);

TextView tv = (TextView)findViewById(R.id.txtRawResource);

tv.setText(readFile(this, R.raw.saga));

}

private static CharSequence readFile(Activity activity, int id) {

BufferedReader in = null;

try {

in = new BufferedReader(new InputStreamReader(

activity.getResources().openRawResource(id)));

String line;

StringBuilder buffer = new StringBuilder();

while ((line = in.readLine()) != null) buffer.append(line).append('\n');

return buffer;

}

catch (IOException e) {

return "";

}

finally {

closeStream(in);

}

}

/**

* Closes the specified stream.

*/

private static void closeStream(Closeable stream) {

if (stream != null) {

try {

stream.close();

} catch (IOException e) {

// Ignore

}

}

}

}

2011-09-10

Christer

+0

让我们看看你的代码。 –

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值