我有一个文本文件,其中包含我需要预加载到 SQLite 数据库中的数据。我保存在 res/raw 中。
我使用 读取整个文件readTxtFromRaw()
,然后使用StringTokenizer
该类逐行处理文件。
但是,String
返回的readTxtFromRaw
不显示文件中的外来字符。我需要这些,因为有些文本是西班牙语或法语。我错过了什么吗?
代码:
String fileCont = new String(readTxtFromRaw(R.raw.wordstext));
StringTokenizer myToken = new StringTokenizer(fileCont , "\t\n\r\f");
readTxtFromRaw 方法是:
private String readTxtFromRaw(Integer rawResource) throws IOException
{
InputStream inputStream = mCtx.getResources().openRawResource(rawResource);
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
int i = inputStream.read();
while (i != -1)
{
byteArrayOutputStream.write(i);
i = inputStream.read();
}
inputStream.close();
return byteArrayOutputStream.toString();
}
该文件是使用 Eclipse 创建的,并且所有字符在 Eclipse 中都可以正常显示。
这可能与 Eclipse 本身有关吗?我设置了一个断点并在 Watch 窗口中检查了 myToken。我试图手动将奇怪的字符替换为正确的字符(例如 í 或 é),但它不会让我这样做。