我应该将我的文件保存在 Android 中的何处以进行本地访问? [英] Where should I save my file in Android for local access?

查看:31
本文介绍了我应该将我的文件保存在 Android 中的何处以进行本地访问?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个数据集,它们当前与我的 Java 文件和我的 PC 位于同一文件夹中.目前,我正在通过我的 C 驱动器访问它们.由于这是一个应用程序,我应该在哪里保存我的 .ARFF 文件以及我应该使用什么路径?我在原始文件夹中尝试过,但似乎没有任何效果.

I have two datasets which are currently in the same folder as my java files AND on my PC. Currently, I am accessing them through my C-drive. Since this is an app, where should I save my .ARFF files and what path should I use instead? I have tried in the raw folder, but nothing seems to work.

这是我目前所拥有的...

Here's what I have so far...

推荐答案

时间过长

从资产文件夹中检索数据的一个非常简单的解决方案!只有一种用户定义的方法.

A very easy solution to retrieving data from the assets folder! Only one user-defined method.

  1. res目录下制作raw文件夹.
  2. 粘贴raw目录
  3. 中的任何文件
  4. 制作一个单独的.java文件
  5. 确保它是一个派生类(在本例中它扩展了AppCompatActivity
  6. 在正文中写下 A 部分
  7. 将 B 部分写在正文之外
  1. Make raw folder in res directory.
  2. Paste whatever files in the raw directory
  3. Make a separate .java file
  4. Make sure it is a derivative class (in this case it extended AppCompatActivity
  5. Write Part A in the body
  6. Write Part B outside the body

A. 这是在 main 函数中或在自定义的 用户定义 函数中.

A. This is in the main function OR in a custom, user-defined function.

BufferedReader bReader;            
bReader = new BufferedReader(
           new InputStreamReader(ISR(R.raw.FILENAME_WITHOUT_TYPE)));

FILENAME_WITHOUT_TYPE 指的是文件的名称,而不是其结尾(后面跟着 . 的所有内容).

FILENAME_WITHOUT_TYPE refers to only the name of the file, not its ending (everything followed by the .).

B.这是 ISR 的定义.

B. This is the definition of ISR.

public InputStream ISR(int resourceId) {
    InputStream iStream = getBaseContext().getResources().openRawResource(resourceId);
    return iStream;
}

就像一个魅力!

资源:

这篇关于我应该将我的文件保存在 Android 中的何处以进行本地访问?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆