Reference a File on your Android Device

How to Reference a File on your Android Device

File was added in API Level 1

An "abstract" representation of a file system entity identified by a pathname. The pathname may be absolute (relative to the root directory of the file system) or relative to the current directory in which the program is running. The actual file referenced by a File may or may not exist. It may also, despite the name File, be a directory or other non-regular file.

1. Create an Android project, if you don't already have one.

2. In the MainActivity.java file, add the below line to the imports section.

import java.io.File;

3. In the onCreate method, add the line below. Replace com.akp.mypackagename is your package name. Replace mySQLiteDatabase.db with your database name, or filename.

File myFile = new File("/data/data/com.akp.mypackagename/mySQLiteDatabase.db"); 

4. Compile and run!

Related Articles:

Resources:
http://developer.android.com/reference/java/io/File.html
http://mobile-development-tutorial.blogspot.com/2012/12/android-external-sqlite-database.html

Web hosting