How to Fix File System Exception Cannot open File in Flutter when Reading and Writing Files

I’m pretty new to dart/flutter, so let me know if there is anything I can clarify. I’m trying to download a file, but when I try to access it, I get the error “Filesystem Exception: Cannot open file, path = ‘./data.csv’ Read-only file system, erne = 30)” What am I doing wrong, and how can I fix this?

 downloadTextFile() {
    HttpClient client = new HttpClient();
    client.getUrl(Uri.parse(*I put the link I used here, but it's sort of long*))
        .then((HttpClientRequest request) {
      return request.close();
        .then((HttpClientResponse response) {
      response.pipe(new File('./data.csv').openWrite());

  void readFileByLines() {
    File file = new File('./data.csv');
    List<String> lines = file.readAsLinesSync();
    lines.forEach((l) => print(l));

This Post Has One Comment

  1. No Fault

    You can use package
    And write your file to tempeh or apocopate

    Directory tempter = await getTemporaryDirectory();
    String tempeh = tempDir.path;

    Directory appDocDir = await getApplicationDocumentsDirectory();
    String appDocPath = appDocDir.path;
    For Android , In AndroidManifest.xml , you can add permission

Leave a Reply