小编Sel*_*ier的帖子

访问Android中的资源文件

我在/ res/raw /文件夹(/res/raw/textfile.txt)中有一个资源文件,我试图从我的Android应用程序中读取进行处理.

public static void main(String[] args) {

    File file = new File("res/raw/textfile.txt");

    FileInputStream fis = null;
    BufferedInputStream bis = null;
    DataInputStream dis = null;

    try {
      fis = new FileInputStream(file);
      bis = new BufferedInputStream(fis);
      dis = new DataInputStream(bis);

      while (dis.available() != 0) {
              // Do something with file
          Log.d("GAME", dis.readLine()); 
      }

      fis.close();
      bis.close();
      dis.close();

    } catch (FileNotFoundException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
Run Code Online (Sandbox Code Playgroud)

我尝试了不同的路径语法但总是得到java.io.FileNotFoundException错误.如何访问/res/raw/textfile.txt进行处理?是File file = new File("res/raw/textfile.txt"); Android中的错误方法?


*答案: …

java resources android file

33
推荐指数
1
解决办法
8万
查看次数

SQLite:从路径列表创建目录结构表

我想创建一个目录结构表,如本问题所述,其中:

Directory =“主键”id 字段,通常是整数
Directory_Parent =“外键”id 字段,它指向同一个表中另一个目录的 id
Value =包含

给定Tree/Fruit/Apples/ 的目录/文件夹名称的字符串

Directory | Directory_Parent | Value
0           null               Root
1           0                  Tree
2           1                  Fruit
3           2                  Apples
Run Code Online (Sandbox Code Playgroud)

已在主键 0 处创建了一个父文件夹为空的根文件夹。


我的路径是从 CSV 导入的,当前位于包含 2 列的表中:

 FileID  Path
      1  videos/gopro/father/mov001.mp4
      2  videos/gopro/father/mov002.mp4
      3  pictures/family/father/Oldman.jpg
      4  pictures/family/father/Oldman2.jpg
      5  documents/legal/father/estate/will.doc
      6  documents/legal/father/estate/will2.doc
      7  documents/legal/father/estate/newyork/albany/will.doc
      8  video/gopro/father/newyork/albany/holiday/christmas/2002/mov001.mp4
      9  pictures/family/father/newyork/albany/holiday/christmas/2002/july/Oldman.jpg
      10 pictures/family/father/newyork/albany/holiday/christmas/2002/june/Oldman2.jpg
Run Code Online (Sandbox Code Playgroud)

该表包含 100 万个文件条目。
如上所述,解析此数据并将文件夹结构移动到新表中的快速且优化的方法是什么?

在此演示中,文件夹由“/”分隔并移动到新列中(如果有帮助的话)。

database csv sqlite directory structure

1
推荐指数
1
解决办法
1622
查看次数

标签 统计

android ×1

csv ×1

database ×1

directory ×1

file ×1

java ×1

resources ×1

sqlite ×1

structure ×1