1- Android Internal Storage
Android Internal Storage: A place to store private data of each application, this data is stored and used for own application. Other applications can not access it. Normally when the application is removed from Android devices, the associated data file is also removed.
Another feature when you work with files in Internal Storage, you can only work with a simple file name, can not work with a file name has the path.
Open file to write:
1 2 3 4 5 6 7 |
|
You have four option for creating mode:
Mode | Description |
MODE_PRIVATE | File creation mode: the default mode, where the created file can only be accessed by the calling application (or all applications sharing the same user ID). |
MODE_APPEND | Mode data appended to the file if it already exists. |
MODE_ENABLE_WRITE_AHEAD_LOGGING | |
| These modes are very dangerous, it's like a security hole in Android, best not to use, you can use alternative techniques such as:
|
| |
| This mode allows multiple processes can be writen to the file. However, it is recommended that you should not use this mode because it does not work on some versions of Android. You can use other techniques:
|
Open file to read data:
1 2 3 4 5 6 |
|
2- Reading and writing data to Internal Storage example
Now you can make an example of writing data to files stored in Internal Storage, and read data from this file.
Create a project named InternalStorageDemo.
The application interface:
activity_main.xml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
|
MainActivity.java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
|
Running app:
Use the "Android Device Manager" you can see the file is created.
See more about "Android Device Manager":
· http://o7planning.org/en/10537/android-device-manager-tutorial
0 件のコメント:
コメントを投稿