Monday, 1 February 2021

opencsv not reading CSV after Android update

My code was working perfectly until my phone updated last night. I'm reading a CSV file from the phones storage into an array in my app using opencsv. This is the code...

    public static String[] getFileContents(File file) {
    String[] contentsArray = new String[500];
    if(file.exists()) {
        try {
            CSVReader reader = new CSVReader(new FileReader(file));
            String[] nextLine;
            while ((nextLine = reader.readNext()) != null) {
                System.arraycopy(nextLine, 0, contentsArray, 0, nextLine.length);
            }
        } catch (Exception e) {
            System.out.println("Failed file: " + file);
            System.out.println("You are here and sad but at least the file exists");
            e.printStackTrace();
        }
    } else {
        System.out.println("File does not exist");
    }

    return contentsArray;
}

and this is the error I'm getting...

I/System.out: Failed file: /storage/emulated/0/Documents/text/36-12644-Test cert-2021.csv
I/System.out: You are here and sad but at least the file exists
W/System.err: java.io.FileNotFoundException: /storage/emulated/0/Documents/text/36-12644-Test cert-2021.csv: open failed: EACCES (Permission denied)

I have changed nothing. Can anyone point me in the right direction to resolve this please? Has something changed in the new update (Android 11) with permissions that is now blocking openCSV from reading the file?



from opencsv not reading CSV after Android update

No comments:

Post a Comment