【问题标题】:How to read a local (res/raw) file line by line?如何逐行读取本地(res / raw)文件?
【发布时间】:2011-03-14 05:54:33
【问题描述】:

我的 res/raw 目录中有一个文本文件。我想逐行读取文件,但由于 Android 的安全限制,FileReader 和 BufferedReader 失败。我还能怎么做?

【问题讨论】:

标签: android file readline filereader


【解决方案1】:

getResources().openRawResource() 返回一个InputStream,应该可用于逐行阅读。

【讨论】:

  • 输入流 inp = this.getResources().openRawResource(R.raw.textfile);叫我愚蠢,但这有方法 read() [读取单个字节]、read(bytes[]) [读取 n 字节] 和 read(byte[], int offset, int length)。没有 readLine()!
  • @Vinay: new BufferedReader(new InputStreamReader(this.getResources.openRawResource(R.raw.textfile)))
【解决方案2】:

DataInputStream 允许您执行 readLine(以及许多其他操作);看 DataInputStream Reference.

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-04-01
    • 2014-06-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多