주식회사 이웃사촌

path_provider + File 을 이용한 화일 읽고/쓰기 본문

Flutter

path_provider + File 을 이용한 화일 읽고/쓰기

(주)이웃사촌 2021. 8. 10. 10:11

dependencies:

  flutter:

    sdkflutter



  # The following adds the Cupertino Icons font to your application.

  # Use with the CupertinoIcons class for iOS style icons.

  cupertino_icons^1.0.2

  path_provider^2.0.2

 

 

 //화일에 내용을 쓴다.

  void writeCountFile(int count) async {

    var dir = await getApplicationDocumentsDirectory();

    File(dir.path + '/count.txt').writeAsStringSync(count.toString());

  }

 

  

 //화일에 내용을 쓴다.

  void writeCountFile(int count) async {

    var dir = await getApplicationDocumentsDirectory();

    File(dir.path + '/count.txt').writeAsStringSync(count.toString());

  }

 

  //화일을 읽어온다.

  void readCountFile() async {

    //읽어올 파일을 지정한다.

 

    try {

      var dir = await getApplicationDocumentsDirectory();

 

      var file = await File(dir.path + '/count.txt').readAsString();

 

      print(file);

 

      setState(() {

        _count = int.parse(file);

      });

    } catch (e) {

      print(e.toString());

    }

  }

반응형
Comments