The read and write operations on folders and files in Android are the same as those in Java. However, you must specify the user's permissions to run the commands on Android. Modify the androidmanifest. xml file and add the following Configuration:
<! -- Permission to write data to sdcard -->
< Uses-Permission Android: Name = "Android. Permission. write_external_storage" > </ Uses-Permission >
<! -- Permission to create/delete files in sdcard -->
< Uses-Permission Android: Name = "Android. Permission. mount_unmount_filesystems" > </ Uses-Permission >
After this configuration, you can operate on a real machine like Java.CompositionAnd Folders:
Public Class Sdcardhelper {
Public Static Void Deletedirectory (string path ){
File dir = New File (PATH );
If (Dir. exists ()){
Dir. Delete ();
}
}
Public Static Boolean Createdirectory (string path ){
File dir = New File (PATH );
If (! Dir. exists ()){
Dir. mkdirs ();
}
If (Dir. exists ()){
Return True ;
} Else {
Return False ;
}
}
Public Static String getdirectory (string subdir ){
String Path = Android. OS. environment. getexternalstoragedirectory ()
. Getabsolutepath () + file. Separator;
Return Path + subdir;
}
Public Static Boolean Hassdcard (){
String status = environment. getexternalstoragestate ();
If (Status. Equals (environment. media_mounted )){
Return True ;
} Else {
Return False ;
}
}
}