我应该将我的文件保存在 Android 中的何处以进行本地访问? [英] Where should I save my file in Android for local access?
问题描述
我有两个数据集,它们当前与我的 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.
- 在
res
目录下制作raw
文件夹. - 粘贴
raw目录
中的任何文件 - 制作一个单独的
.java
文件 - 确保它是一个派生类(在本例中它扩展了
AppCompatActivity
- 在正文中写下 A 部分
- 将 B 部分写在正文之外
- Make
raw
folder inres
directory. - Paste whatever files in the
raw directory
- Make a separate
.java
file - Make sure it is a derivative class (in this case it extended
AppCompatActivity
- Write Part A in the body
- 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;
}
就像一个魅力!
资源:
- https://inducesmile.com/android-programming/how-to-read-a-file-from-raw-directory-in-android/
- https://gist.github.com/Airfixed/799e784696b0a60c43a34213d
这篇关于我应该将我的文件保存在 Android 中的何处以进行本地访问?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!