Files copied using Files.copy API are not visible in Gallery


I am using Files.copy API (package: java.nio.file) for copying images to new directory. The operation is working fine and I can see files are copied properly in new directory. But those newly copied files are not visible in Gallery by default.

If if use default file manager and try to move those newly copied files again in new folder then that new folder is immediately visible in phone gallery.

Do I need any change here? or I am missing something ?

Code snippet which I am using:

for (Path srcPath : sourcePaths) {
                String fileName = srcPath.getFileName().toString();
                File targetFile = new File(SDCARD_PATH + TARGET_PATH + fileName);

                if (!fileName.equalsIgnoreCase(".nomedia") && !targetFile.exists()) {
                    Files.copy(srcPath, targetFile.toPath(), StandardCopyOption.COPY_ATTRIBUTES);


try to rename files it might work
image visibility

Answered By – vaimalaviya

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published