Tengo un archivo example.tar.gz y necesito copiarlo a otra ubicación con un nombre diferente example_test.tar.gz. Probé conCopie y cambie el nombre del archivo en una ubicación diferente
private void copyFile(File srcFile, File destFile) throws IOException
{
InputStream oInStream = new FileInputStream(srcFile);
OutputStream oOutStream = new FileOutputStream(destFile);
// Transfer bytes from in to out
byte[] oBytes = new byte[1024];
int nLength;
BufferedInputStream oBuffInputStream =
new BufferedInputStream(oInStream);
while ((nLength = oBuffInputStream.read(oBytes)) > 0)
{
oOutStream.write(oBytes, 0, nLength);
}
oInStream.close();
oOutStream.close();
}
}
donde
String from_path=new File("example.tar.gz");
File source=new File(from_path);
File destination=new File("/temp/example_test.tar.gz");
if(!destination.exists())
destination.createNewFile();
y luego
copyFile(source, destination);
pero no funciona. La ruta está bien. Imprime que los archivos existen. ¿Alguien puede ayudar?
tratan 'flush()' 'sus fuentes antes de cerrar()' ing ella. –
Corrija este código en su publicación: 'String from_path = new File (" example.tar.gz ");' –
@Mohamed, flush no es necesario antes de cerrar – bestsss