Java 读取文件路径android studio

Java 读取文件路径android studio,java,android,weka,Java,Android,Weka,嗨,我还是android编程的新手。我想知道如何在android代码中读取像“/home/emulator/0/blabla/file.txt/”这样的文件路径。我需要知道如何读取文件路径,因为我必须从我将要制作的应用程序访问android上的特定文件。并且路径已经在代码中定义,因此用户将只获得读取的输出 public void naivebayes() throws Exception { //im using weka to read a .arff file

嗨,我还是android编程的新手。我想知道如何在android代码中读取像“/home/emulator/0/blabla/file.txt/”这样的文件路径。我需要知道如何读取文件路径,因为我必须从我将要制作的应用程序访问android上的特定文件。并且路径已经在代码中定义,因此用户将只获得读取的输出

public void naivebayes() throws Exception {
        //im using weka to read a .arff file
        //the problem is i didnt know how to "write" the path, from where i should start it
         //p.s: i already tried open the files on my phone then clikc "Details" to see the path on the             phone and write it on the code but the code still could'nt read the files
        DataSource source = new DataSource("File Path");

        Instances dataset = source.getDataSet();
        //set class index to the last Attributes
        dataset.setClassIndex(dataset.numAttributes()-1);
        //create and build the classifier
        NaiveBayes nb = new NaiveBayes();
        nb.buildClassifier(dataset);
        tv.setText(nb.getCapabilities().toString());
    }

不要使用硬编码文件路径。框架将为您提供要保存文件的区域的基本路径

对于SD卡,请使用
Environment.getExternalStorageDirectory()

对于本地文件,请使用
Context.getFilesDir()
(或
Context.openFileOutput(字符串名称,int模式)
等)


对于本地缓存,使用
Context.getCacheDir()

,所以基本上,我必须将文件放在模拟器上?