(SOLVED) 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