Code for copying folders:
Public Boolean copy (string file1, string file2 ){
File in = new file (file1 );
File out = new file (file2 );
If (! In. exists ()){
Return false;
}
Else {
}
If (! Out. exists ())
Out. mkdirs ();
File [] file = in. listfiles ();
Fileinputstream fin = NULL;
Fileoutputstream fout = NULL;
For (INT I = 0; I <file. length; I ++ ){
If (file [I]. isfile ()){
Try {
Fin = new fileinputstream (file [I]);
} Catch (filenotfoundexception e ){
// Todo auto-generated Catch Block
E. printstacktrace ();
}
Try {
File F = new file (file2 + "/" + file [I]. getname ());
Fout = new fileoutputstream (f );
} Catch (filenotfoundexception e ){
// Todo auto-generated Catch Block
E. printstacktrace ();
}
Int C;
Byte [] B = new byte [1, 1024*5];
Try {
While (C = fin. Read (B ))! =-1 ){
Fout. Write (B, 0, C );
}
Fin. Close ();
Fout. Flush ();
Fout. Close ();
} Catch (ioexception e ){
// Todo auto-generated Catch Block
E. printstacktrace ();
}
// Return true;
}
Else copy (file1 + "/" + file [I]. getname (), file2 + "/" + file [I]. getname ());
}
Return false;
}
There are two ways to set folder permissions on Android:
1:
Try {
String command = "chmod 644" + F. getabsolutepath ();
Runtime runtime = runtime. getruntime ();
Java. Lang. Process proc = runtime.exe C (command );
} Catch (ioexception e ){
E. printstacktrace ();
}
2:
When fileutils is used, this class is hidden by default. The official SDK does not contain this class. Therefore, to use this class for code, you need to compile the project in the android source code.
Fileutils. setpermissions (F. getabsolutepath (), fileutils. s_irusr | fileutils. s_iwusr | fileutils. s_irgrp | fileutils. s_iroth,-1,-1 );