Tutorial by Examples

You can get your working folder by calling the method getFilesDir() on your Activity (Activity is the central class in your application that inherits from Context. See here). Reading is not different. Only your application will have access to this folder. Your activity could contain the following c...
File myFile = new File(getFilesDir(), "myData.bin"); FileOutputStream out = new FileOutputStream(myFile); // Write four bytes one two three four: out.write(new byte [] { 1, 2, 3, 4} out.close() There is nothing Android specific with this code. If you write lots of small ...
The old good Java object serialization is available for you in Android. you can define Serializable classes like: class Cirle implements Serializable { final int radius; final String name; Circle(int radius, int name) { this.radius = radius; this.name = name; }...
You can also read and write from/to memory card (SD card) that is present in many Android devices. Files in this location can be accessed by other programs, also directly by the user after connecting device to PC via USB cable and enabling MTP protocol. Finding the SD card location is somewhat more...
If you create files for exporting via USB cable to desktop using MTP protocol, may be a problem that newly created files are not immediately visible in the file explorer running on the connected desktop PC. To to make new files visible, you need to call MediaScannerConnection: File file = new File(...
Small files are processed in a fraction of second and you can read / write them in place of the code where you need this. However if the file is bigger or otherwise slower to process, you may need to use AsyncTask in Android to work with the file in the background: class FileOperation extends A...

Page 1 of 1