Internal storage


Internal storage

In internal storage, you use a file system to save your data. References to File objects are simply available for virtually storing any kind of data by the means of a FileOutputStream. The exceptionality of this storage that makes it unique is that the contents are secured in your app. If you need to check the data, there is a Context getFilesDir() method that can be used in the internal storage directory.

To generate a directory inside the internal file directory, you can utilize the getDir(directoryName, Context.MODE_XXX) technique. If the file is absent, the getDir() generates it and retrieves a reference to a File object that represents a particular directory.

In order to read the files, use the reading method that you like. Nevertheless, in this example, we have used a scanner object to read the files. If you want to read them directly in your internal storage directory, the openFileInput(fileName) method will aid you.

Code

JAVA File directory; if (filename.isEmpty()) { directory = getFilesDir(); }else { directory = getDir(filename, MODE_PRIVATE);} File[] files = directory.listFiles(); JAVASCRIPT FileInputStream fis = openFileInput(filename); Scanner scanner = new Scanner(fis); scanner.useDelimiter("\\Z"); String content = scanner.next(); scanner.close();

Image

Image Not Found