Android provides an existing mechanism for accessing private files while controlling their access modes: Context.openFileOutput and Context.openFileInput. As a Source/Sink primer, here's a cool way to adapt between the two:
The usage would look like this:
AndroidPrivateFileGuavaAdapter adapter =
new AndroidPrivateFileGuavaAdapter("filename", Context.MODE_PRIVATE, context);
// Read all text
String contents = adapter.asCharSource().read();
// Write some bytes
byte[] bytes = ...; // obtains bytes from somewhere
adapter.asByteSink().write(bytes);
No comments:
Post a Comment