简体   繁体   English

Flutter Dart 文件路径

[英]Flutter Dart File path

quick Flutter Dart issue.快速 Flutter Dart 问题。

I am trying to read from a text file located inside the app's directory, however Flutter does not recognize a single file path that I provide it.我正在尝试读取位于应用程序目录内的文本文件,但是 Flutter 无法识别我提供的单个文件路径。 The file path is always responded to with "OS Error: No such file or directory, errno = 2".文件路径总是用“操作系统错误:没有这样的文件或目录,errno = 2”来响应。

I am trying to read from a file located in assets/importfiles, from a dart class inside lib/viewmodels.我正在尝试从位于 assets/importfiles 中的文件中读取,从 lib/viewmodels 中的 dart class。 The assets directory has already been added to pubsec.yaml.资产目录已经添加到 pubsec.yaml。

Here is the picture of my directory structure这是我的目录结构的图片

I can even have the main class locate and print out the files' paths using rootBundle, but trying to initialize a new File using those paths provides the same error text.我什至可以让主要的 class 使用 rootBundle 定位并打印出文件的路径,但是尝试使用这些路径初始化新文件会提供相同的错误文本。 If I were to use path provider to locate and read from files, how would I initially put the files into the Temporary Directory or Application Documents Directory, if Flutter does not recognize the file paths of the files that I want to insert?如果我要使用路径提供程序来定位和读取文件,如果 Flutter 无法识别我要插入的文件的文件路径,我最初如何将文件放入临时目录或应用程序文档目录?

Have you tried putting a "/" before "assets" in the file path?您是否尝试过在文件路径中的“资产”之前放置一个“/”? I'm not sure that this will fix the error, let me know if it works!我不确定这是否会修复错误,让我知道它是否有效!

Just You need to remove folder name ''.只是您需要删除文件夹名称“”。

assets\importfiles 

在此处输入图像描述

to

assets Or importfiles

在此处输入图像描述

Thanks You.Happy To help you谢谢您。很高兴为您提供帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM