I have a pure java program that encrypts files from a specific directory (in this case the sdCard) and I'm running it on Android Oreo 8.1 with the IDE for Android called AIDE (it's not an Android application, it's pure Java) , and there is a block of code that deletes the original file but I have an exception. What can I do?
CODE:
public static void deleteFiles( String file ) throws IOException
{
try
{
Files.deleteIfExists( Paths.get( file ) );
}
catch( NoSuchFileException e )
{
System.out.println("No such file exists");
}
}
This is the error that launches:
java.nio.file.AccessDeniedException: /storage/4A80-16E6/qwerty/test.mp4 at sun.nio.fs.UnixFileSystemProvider.implDelete (UnixFileSystemProvider.java:244) at sun.nio.fs.AbstractFileSystemProvider.deleteIfExists (AbstractFileSystemProvider.java:108) at java.nio.file.Files.deleteIfExists (Files.java:1165) at encryptiondecryptionfile.ExecCrypto.deleteFiles (ExecCrypto.java:226) at encryptiondecryptionfile.ExecCrypto.encrypt (ExecCrypto.java:97) at encryptiondecryptionfile.ExecCrypto.main (ExecCrypto.java:34) at java.lang.reflect.Method.invoke (Native Method) at com.aide.ui.build.java.RunJavaActivity $ 1.run (SourceFile: 108) at java.lang.Thread.run (Thread.java:764)
THE PACK OF THE FOLDER IS: /storage/4A80-16E6/qwerty/test.mp4