There are many times when you need to combine Java’s original packages with tools that are unique to Android. For example, when you want to read a file from persistent storage, you can use Java’s io and nio packages to actually read the file, but you’ll also need to use Android’s unique classes and methods to work with the local file system or application package. In this example I’ll show you how to include a text file in an app’s assets folder, and then open and read its contents at runtime.
- There are many situations in Android development…where you need to combine Java's…original run-time packages…with tools that are unique to Android.…For example, when you want to…read a file from persistent storage…you can use Java's own packages…to actually read the file,…but you'll also use Android's unique classes…and methods to work with the local file system…or application package.…In this demonstration I'll show you…how to include a text file in an app's assets folder…and then open and read the files contents at run time.…
This project, read from assets,…already has an assets folder…and it contains a single file called loren_ipsum.txt.…It's a plain text file with a couple of paragraphs of text.…I'm going to read the file using classes from Java.IO,…but I'll use a method of the Android SDK…to actually get to that file.…In the main activity class I'll start…by creating a new method at the bottom.…It'll be private and it'll return a string…and it's name will be readFileFromAssets.…
It'll receive a single argument, a string value,…
Watch these Java tutorials to learn smarter, more efficient methods for Android app development.
- Preparing the development environment
- Packaging and running Android apps
- Optimizing Java code for Android
- Implementing event handler interfaces
- Defining custom callback methods
- Working with the Android SDK's Java packages
- Storing data
- Reading text files
- Parsing JSON and XML data
- Managing device sensors
- Playing audio