There are many situation where we end up having data to be read from external files, external file can be either an excel file (for reading data for data driven test) or an properties file (for reading configuration details)
As for Selenium is concerned, the external file can be read as normal as any JAVA application as we do, we can pass the relative path of the file and access the file.
But, for Android the case is different, to access any external file, we need that file to be available in assets
directory of the project. Assets directory is a special directory which is created automatically for any android project (can be application development or test project) and this folder can contain any external resources or assets, in our case its excel or properties file.
Here is how the assets file looks like in one of my project
Well, here is how it works, every time you try to access the external file in android test project, you need to get the assets from the available resources and open the file (which is basically a stream)
Here is the code snippet to do that
InputStream datastream = getInstrumentation().getContext().getResources()
As you can see the above code, I am getting the current context using getInstrumentation() and then getting assets from getResources() method and opening the specified file.
With this we can read the external files in Android, this will come handy while working with data driven test for Android.