我如何仅读取扑朔迷离的文件内容的间隔?
我正在操纵文件以将信息存储在flutter中的应用中。例如,目的考虑一个带有以下项目为字符串的文件.txt:
[ value 1, value 2, value 3, value 4, ... value 500, ]
在此读取中我的应用程序应该非常快,我正在寻找一种仅读取此文件范围的方法,例如从项目0到项目20。您是否可以在不将文件的全部值投入var的情况下做到这一点?我想在达到极限后立即停止阅读。 目前,我使用路径提供商这样做:
Future<String> load() async {
final Directory directory = await getApplicationDocumentsDirectory();
final File file = File('${directory.path}/names.txt');
return await file.readAsString();
}
i'm manipulating a file to store information in the app in flutter. For example purposes consider a file .txt with the following items as String:
[ value 1, value 2, value 3, value 4, ... value 500, ]
my app should be very quick in this reading, I'm looking for a way to read only a range of this file, for example from item 0 to item 20. Would you have a way to do this without throwing the entire value of the file into a var? I'd like to stop reading as soon as I've reached the limit.
currently i do that way with path provider:
Future<String> load() async {
final Directory directory = await getApplicationDocumentsDirectory();
final File file = File('${directory.path}/names.txt');
return await file.readAsString();
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您只想读取文件的部分,则需要 随机访问a>,因此您需要使用
file> file.file.open < /code>
/
file>
file.opensync
获得 :
另外,您可以使用
file.openread
创建一个读取指定文件的一部分的流
。If you want to read only portions of a file, you need random access, and thus you need to use
File.open
/File.openSync
to obtain aRandomAccessFile
:Alternatively you could use
File.openRead
to create aStream
that reads a portion of the specified file.