O'Reilly logo

Xamarin Mobile Development for Android Cookbook by Matthew Leibowitz

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Using files and the filesystem

Many apps require access to the filesystem for accessing databases, reading content, and many other reasons.

How to do it...

There are two main areas for storing files: internal storage and external storage. Making use of the internal storage or app sandbox is very easy:

  1. Writing files to the filesystem is very simple, and all that is required is the path to the sandbox for our app:
    string sandbox = FilesDir.AbsolutePath;
  2. Once we have this path, we can use the types from the .NET BCL to manipulate the files:
    string file = Path.Combine(sandbox, "myFile.txt");
    bool exists = File.Exists(file);
    File.WriteAllText(file, "this is my value");
    string value = File.ReadAllText(file);
  3. Sometimes, we only need to store files temporarily. ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required