Android: copying files from one directory to another
It runs good after amended in the following way:
button1_save.setOnClickListener(new OnClickListener()
{
public void onClick(View v)
{
String sourcePath = Environment.getExternalStorageDirectory().getAbsolutePath() + "/TongueTwister/tt_temp.3gp";
File source = new File(sourcePath);
String destinationPath = Environment.getExternalStorageDirectory().getAbsolutePath() + "/TongueTwister/tt_1A.3gp";
File destination = new File(destinationPath);
try
{
FileUtils.copyFile(source, destination);
}
catch (IOException e)
{
e.printStackTrace();
}
}
});
In API level 29, android added FileUtils class, which has copy function.
Use this code to copy your file:-
public void copyFile(File source, File destination) throws IOException {
FileUtils.copy(new FileInputStream(source), new FileOutputStream(destination));
}
If Android Studio does not find FileUtils class, that means your compileSdkVersion is lower than 29, in this case, you have to upgrade your compileSdkVersion.
For upgrading, go to your app-level build.gradle file and replace the old compileSdkVersion with 29
Like this
compileSdkVersion 29
For more info about FileUtils class, visit Android Developer Website https://developer.android.com/reference/android/os/FileUtils