'Flutter Dart File path

quick Flutter Dart issue.

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. The file path is always responded to with "OS Error: No such file or directory, errno = 2".

I am trying to read from a file located in assets/importfiles, from a dart class inside lib/viewmodels. The assets directory has already been added to 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. 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?



Solution 1:[1]

Just You need to remove folder name ''.

assets\importfiles 

enter image description here

to

assets Or importfiles

enter image description here

Thanks You.Happy To help you

Solution 2:[2]

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!

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 JEMISH VASOYA
Solution 2 theFreeman96