.NET MAUI › Local Storage & Data

How do you read and write files in MAUI cross-platform?

Intermediate

Answer

Use System.IO with paths from FileSystem.AppDataDirectory (private, persistent) or CacheDirectory (disposable). For files bundled with the app, use FileSystem.OpenAppPackageFileAsync since packaged assets aren't regular filesystem paths on all platforms.
string path = Path.Combine(FileSystem.AppDataDirectory, "data.json");
await File.WriteAllTextAsync(path, json);

using var stream = await FileSystem.OpenAppPackageFileAsync("seed.json");
Real-world example An app writes user data to AppDataDirectory and reads a bundled seed file via OpenAppPackageFileAsync on first run.

Common follow-ups: AppDataDirectory vs CacheDirectory? | How do you read a packaged file?