Unhandled Exception: FileSystemException: Directory listing failed, path = '/storage/emulated/0/Download/' (OS Error: Permission denied, errno = 13) - flutter

I have the below code that I want to read all music in downloads but it's giving the above error. What can be the problem
final dartFile = Glob("/storage/emulated/0/Download/**.mp3");
for (var entity in dartFile.listSync()) {
print(entity.uri);
}
Below is my manifest file

Related

FileSystemException (FileSystemException: Cannot open file, path = 'file.txt' (OS Error: No such file or directory, errno = 2))

readLrTime() async {
Directory fileDic = await getApplicationDocumentsDirectory();
String filePath = fileDic.path;
File file = File("$filePath/file.txt");
var lines = await file.readAsLines();
var mylrTime = lines[0];
return mylrTime;
}
this is my code and I've faced this error
FileSystemException (FileSystemException: Cannot open file, path = 'file.txt' (OS Error: No such file or directory, errno = 2))
Check if you have added read and write permissions on the android manifest file.
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<application...

Flutter cannot find the path that I already add in pubsec.yaml

void executeTreatments() {
var treatmentList = [];
File('lib/asset/treatments.txt')
.openRead()
.map(utf8.decode)
.transform(new LineSplitter())
.forEach((l) => print(l));
}
The error I get is "[VERBOSE-2:ui_dart_state.cc(209)] Unhandled Exception: FileSystemException: Cannot open file, path = 'lib/assets/treatments.txt' (OS Error: No such file or directory, errno = 2)enter image description here"
Add assets in your pub spec.yaml finlike this.
assets:
- assets/
and then use it like this.
File('assets/treatments.txt')

ERROR:flutter/lib/ui/ui_dart_state.cc(209) Unhandled Exception: FileSystemException: Cannot open file, path ='./data/filename.mvt'

I am trying to read the data from .mvt file by using the below code
#override
Future<DatastoreReadResult?> readLabelsSingle(Tile tile) async {
VectorTile tiles = await VectorTile.fromPath(path: './mapsforge_flutter/lib/src/data/6160.mvt');
VectorTileLayer layer =
tiles.layers.firstWhere((layer) => layer.name == 'building');
layer.features.forEach((feature) {
feature.decodeGeometry();
if (feature.geometryType == GeometryType.Point) {
var geojson = feature.toGeoJson<GeoJsonPoint>(x: 4823, y: 6160, z: 14);
print(geojson?.type);
print(geojson?.properties);
print(geojson?.geometry?.type);
print(geojson?.geometry?.coordinates);
print('\n');
}
});
but after running the code i am getting bellow error
E/flutter ( 1225): [ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception: FileSystemException: Cannot open file, path = './mapsforge_flutter/lib/src/data/6160.mvt' (OS Error: No such file or directory, errno = 2)
My folder structure are as below which are on my desktop
mapsforge_flutter
└───mapsforge_flutter
└───lib
└───src
└───data(file is here)
Please help me to resolve the error

Unhandled Exception: FileSystemException: Cannot retrieve length of file in flutter

When I try to rename a File it throws a FileSystemException. This is the exception:
E/flutter (12252): [ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception: FileSystemException: Cannot retrieve length of file, path = '' (OS Error: No such file or directory, errno = 2)
This is the code:
for (String path in _files.paths) {
for (File file in _pickedFiles) {
if(file.path == path) {
await _pickedFiles.last.rename(_path.withoutExtension(file.path) + '()' + _path.extension(file.path));
}
}
}

Trying to create a new text file in Flutter

I am trying to create a new file and write to it in Flutter and I get an error that states:
[ERROR:flutter/lib/ui/ui_dart_state.cc(177)] Unhandled Exception: FileSystemException: Cannot create file, path = '/data/user/0/com.micharski.d_ball/app_flutter/levels/level101.json' (OS Error: No such file or directory, errno = 2)
Here is my code (I am using the path_provider plugin):
class LevelFactory {
Level level;
File levelFile;
Future<File> _createLevelFile() async {
Directory appDocDir = await getApplicationDocumentsDirectory();
String appDocPath = appDocDir.path;
File file = File('levels/level101.json');
return file.create();
}
Future<void> createLevel() async {
if(level != null){
level = null;
}
levelFile = await _createLevelFile();
print(levelFile);
}
}
Inside the driver class:
var customLvl = new LevelFactory();
customLvl.createLevel();
For debugging purposes, I added this to _createLevelFile():
Directory dir2 = Directory('$appDocPath/levels');
print('DIR2 PATH: ${dir2.absolute}');
My output is now this:
I/flutter ( 7990): DIR2 PATH: Directory: '/data/user/0/com.micharski.d_ball/app_flutter/levels'
E/flutter ( 7990): [ERROR:flutter/lib/ui/ui_dart_state.cc(177)] Unhandled Exception: FileSystemException: Cannot create file, path = '/data/user/0/com.micharski.d_ball/app_flutter/levels/level101.json' (OS Error: No such file or directory, errno = 2)
File paths in Flutter can't be relative. The mobile operating system will interpret paths like "levels/level101.json" as either an invalid path or a path to a location that your app doesn't have permission to access. You need to use a plugin like path_provider to get the path to your app's local data folder and then build absolute paths from that.
import 'package:path_provider/path_provider.dart';
Future<File> _createLevelFile() async {
Directory appDocDir = await getApplicationDocumentsDirectory();
String appDocPath = appDocDir.path;
File file = File('$appDocPath/levels/level101.json');
return await file.create();
}