Ciao,
Sostituire un file? Prima controlli se esiste, eventualmente lo cancelli e lo copi.
Una roba del genere (sto scrivendo dal cell, fai un check sulla sintassi):
codice:
private String PATH_FILEORIGINE = "/data/data/com.tua.origine/";
private String PATH_FILEDESTINAZIONE = "/data/data/com.tua.destinazione/";
[...]
public void copiaFile() {
File fileOrigine = new File (PATH_FILEORIGINE + "nomefileorigine");
File fileDestinazione = new File (PATH_FILEDESTINAZIONE + "nomefiledestinazione");
If (fileDestinazione.exists()){
fileDestinazione.delete();
InputStream orig = new InputStream(PATH_FILEORIGINE + "nomefileorigine");
OutputStream dest = new FileOutputStream(PATH_FILEDESTINAZIONE + "nomefiledestinazione");
* *byte[] buffer = new byte[1024];
* *int length;
while ((length = orig.read(buffer))>0){
*dest.write(buffer, 0, length);
}*
* *dest.flush();
* *dest.close();
* *orig.close();
}
}
Inviato dal mio Galaxy Nexus con Tapatalk 2