今日已更新 362 条资讯 | 累计 38219 条内容
关于我们

标签:#filesystem

找到 1 篇相关文章

AI 资讯

File System Management in Dart

It's a good time to also investigate a bit the dart I/O interfaces, especially the one related to files. The dart:io package must be imported to deal with files and directories in Dart. import 'dart:io' ; A file in Dart is an object instantiated by the File class . This object can be created by simply invoking the default constructor , where its argument will be a String . // default constructor can be used // to create a new object pointing to // a local file. File myFile = File ( "./file1.test" ); fromRawPath() is another constructor, it opens a file based on an List<Uint8> ( Uint8List ), this kind of data is usually generated by utf8.encode or ascii.encode . // fromRawPath constructor can be used // to open a file based on a raw path, // an Uint8list. File myFile2 = File . fromRawPath ( ascii . encode ( "./file2.test" ); ); Finally, the fromUri() constructor will open a file based on an Uri object. // fromUri is another construct that // can be used to open a file based on // an Uri. File myFile3 = File . fromUri ( Uri . file ( "./file3.test" ) ); Now the file object has been created, many attributes and methods are available to control it. Let check first the attributes. In the previous examples, all objects are using a relative path, when the object is returned, the absolute path attribute is set. It is the absolute path representation of the data previously passed. print ( myFile1 . absolute ); print ( myFile2 . absolute ); print ( myFile3 . absolute ); $ dart run File: '/home/user/tmp/cboring/./file1.test' File: '/home/user/tmp/cboring/./file2.test' File: '/home/user/tmp/cboring/file3.test' The original path passed as first argument can be retrieved with the path attribute . print ( myFile1 . path ); print ( myFile2 . path ); print ( myFile3 . path ); $ dart run ./file1.test ./file2.test file3.test The file object can also returns an Uri object with the help of the uri attribute . // this is a closure helper to show // the properties from an Uri object and //

2026-09-01 原文 →