把二进制内容写到文件中

2035次阅读  |  发布于5年以前

把二进制内容写到文件中

Use the File writeAsBytes() method to write bytes to a file.

import 'dart:io';
import 'dart:convert';

main() async {
  final string = 'Dart!';

  // Encode to UTF8.
  var encodedData = UTF8.encode(string);
  var file = await new File('file.txt');
  file.writeAsBytes(encodedData);
  var data = await file.readAsBytes();

  // Decode to a string, and print.
  print(UTF8.decode(data)); // Prints 'Dart!'.
}

Copyright© 2013-2019

京ICP备2023019179号-2