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

查看:464
本文介绍了我应该将文件保存在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...

推荐答案

After too many hours

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

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


  1. 在<$ c $中创建 raw 文件夹c> res 目录。

  2. 粘贴 raw目录
  3. $ b $中的所有文件b
  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。这是IS的定义R。

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

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

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