I ask this question to know how to copy the content of a file that is in the Assets folder, but my method gives an error because it should at least return a true value, but nothing is returned and my code is not loaded:
//Este es el método que hago mención desde un boton y el botón funciona
private boolean Copiar55(File a , File b, File c) throws IOException{
final int CHUNK_SIZE = 1024 * 4;
InputStream is=getAssets().open("texto1.txt");
OutputStream os = new BufferedOutputStream(new FileOutputStream(a));
byte[] chunk = new byte[CHUNK_SIZE];
int bytesLeidos = 0;
while ( (bytesLeidos = is.read(chunk)) > 0) {
os.write(chunk, 0, bytesLeidos);
}
os.close();
String si="si";
InputStream is1=getAssets().open("texto2.txt");
OutputStream os1 = new BufferedOutputStream(new FileOutputStream(b));
byte[] chunk1 = new byte[CHUNK_SIZE];
int bytesLeidos1 = 0;
while ( (bytesLeidos1 = is1.read(chunk1)) > 0) {
os.write(chunk1, 0, bytesLeidos1);
}
os1.close();
InputStream is2=getAssets().open("texto3.txt");
OutputStream os2 = new BufferedOutputStream(new FileOutputStream(b));
byte[] chunk2 = new byte[CHUNK_SIZE];
int bytesLeidos2 = 0;
while ( (bytesLeidos2 = is2.read(chunk1)) > 0) {
os.write(chunk2, 0, bytesLeidos2);
}
os2.close();
return true;
}
//Esto es lo que utilizo para llamar a mi método desde el boton
if(Copiar55(a,b,c)){
}
If you notice where I fail or know another way. Please let me know.
Your method receives 3 files, it is supposed that from these you generate an InputStream, not to use it as a destination:
You can use the method described here , where you define the file path and the path to external storage (this method copies exclusively to external storage):