0

So I know that one of the ways to define a file reader is by saying:

    FileReader file = new FileReader(f);

where f is a file class. In my code, I create the file class just before I define the fileReader, and it gives me a FileNotFoundException.

Here is the code that is giving me problems:

    InputStream inputStream = getResources().openRawResource(R.raw.stats);
    String baseDir = android.os.Environment.getExternalStorageDirectory().getAbsolutePath();
    String fileName = "com/example/magulo/testing123/stats.csv";
    String filePath = baseDir + File.separator + fileName;

    File f = new File(filePath);
    FileReader file = new FileReader(f); //this throws FileNotFound
    CSVReader reader = new CSVReader(file);

This is in the protected void onCreate. Stats.csv is a file which is in both a folder named raw in res and is also copied in the same folder as the erroring-code, the java folder. Why is the fileReader not finding the file? The file is declared without any problems...

1 Answers1

0

String fileName = "com/example/magulo/testing123/stats.csv";

String filePath = baseDir + File.separator + fileName;

File f = new File(filePath);

if(!f.exits) {enter code here f.mkidr();

}

zhang
  • 41
  • 2
  • by the enter code here, do you mean declare the file reader inside the if statement? because i do that and i still get a file not found exception... – user3236874 Aug 18 '16 at 20:46