J'essaie de copier le fichier dans android.J'ai le chemin du fichier.Je veux copier dans un autre dossier avec un nom de fichier différent.J'utilise le code ci-dessous, mais il doesn ' t work.My fichier est un fichier vidéo. Je reçois ERROR-Copie de fichier et enregistrement avec un nom de fichier différent
/storage/emulated/0/testcopy.mp4: open failed: EISDIR (Is a directory)
Ci-dessous est mon code
File source=new File(filepath);
File destination=new File(Environment.getExternalStorageDirectory()+ "/testcopy.mp4");
copyFile(source.getAbsolutePath(),destination.getAbsolutePath());
private void copyFile(String inputPath, String outputPath) {
InputStream in = null;
OutputStream out = null;
try {
//create output directory if it doesn't exist
File dir = new File (outputPath);
if (!dir.exists())
{
dir.mkdirs();
}
in = new FileInputStream(inputPath);
out = new FileOutputStream(outputPath);
byte[] buffer = new byte[1024];
int read;
while ((read = in.read(buffer)) != -1) {
out.write(buffer, 0, read);
}
in.close();
in = null;
// write the output file (You have now copied the file)
out.flush();
out.close();
out = null;
} catch (FileNotFoundException fnfe1) {
Log.e("tag", fnfe1.getMessage());
}
catch (Exception e) {
Log.e("tag", e.getMessage());
}
}