我应该在哪里保存我的文件在 Android 中以供本地访问?

2022-01-24 00:00:00 weka save android-studio java arff

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

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. 制作一个单独的.java文件
  4. 确保它是一个派生类(在这种情况下它扩展了 AppCompatActivity
  5. 在正文中写 A 部分
  6. 将 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 函数中或在自定义的 user-defined 函数中.

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的定义.

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

像魅力一样工作!

资源:

  • https://inducesmile.com/android-programming/how-to-read-a-file-from-raw-directory-in-android/
  • https://gist.github.com/Airfixed/799e784696b0a60c5423d347bf33a341

相关文章