问题描述
我有两个数据集,它们当前与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.
- 在<$ c $中创建
raw
文件夹c> res 目录。 - 粘贴
raw目录
$ b $中的所有文件b - 制作一个单独的
.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。这是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的哪里进行本地访问?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!