Hi I am having trouble with some file handling in Xamarin forms. Each time I run my code I keep getting the systemIO FileNotfound exception. The code I am using is below. The stuff about routerDB is part of a pathfinding NuGet package I am using called Itinero. Before my code can even reach the create routerDb.LoadOsmData line it keeps getting stuck at line 4 and returning the error: System.IO.FileNotFoundException: 'Could not find file "/Date\wales-latest.osm.pbf"'
Here is the the absolute path of that file "wales-latest.osm.pbf" in Xamarin forms.
C:\USW Pathfinder\USW Pathfinder\USW Pathfinder\bin\Debug\Date
I was so frustrated this did not work that I created another program but this time a windows forms one and I entered the same code as below and it worked first time flawlessly and created me the file wales.router.db as I expected.
Here is the absolute path of that file "wales-latest.osm.pbf" in Windows forms.
C:\Users\MYNAME\Desktop\Pathfinder\Pathfinder\bin\Debug\Date
I have also tried simpler file handling code in Xamarin forms to see if I can reach any file as shown in the second code block and I am always met with file not found.
Please can anyone suggest why this would be?
private void LoadButton_OnClicked(object sender, EventArgs e) { var routerDb = new RouterDb(); using (var stream = new FileInfo(@"Date\wales-latest.osm.pbf").OpenRead()) { // create the network for cars. routerDb.LoadOsmData(stream, Vehicle.Car); } // write the routerdb to disk. using (var stream = new FileInfo(@"wales.routerdb").Open(FileMode.Create)) { routerDb.Serialize(stream); }; } public void ReadButton_OnClicked(object sender, EventArgs e) { File.ReadAllText(@"Date\wales-latest.osm.pbf"); } https://stackoverflow.com/questions/66897018/xamarin-forms-osm-file-system-io-file-not-found-exception April 01, 2021 at 08:37AM
没有评论:
发表评论