阅读Android的原始文本文件 [英] Reading Android raw text file
本文介绍了阅读Android的原始文本文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有我已经把我的 RES /原料文件夹 words.txt
文件。该文件中的单词之间用空格分隔。我有一个很难写的的Android / Java的code 以读取字的文件字。
I have a words.txt
file which I have placed in my res/raw folder. The words in the file are separated by space. I'm having a hard time writing the Android/Java code to read the file word by word.
推荐答案
最简单的就是使用的扫描仪。
Scanner s = new Scanner(getResources().openRawResource(R.raw.text_file));
try {
while (s.hasNext()) {
String word = s.next();
// ....
}
} finally {
s.close();
}
缺省的分隔符是空白(包括空格)。如果你想让它在空间的使用只触发 s.useDelimiter();
创建后
这篇关于阅读Android的原始文本文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文