Support Questions
Find answers, ask questions, and share your expertise
Announcements
Alert: Welcome to the Unified Cloudera Community. Former HCC members be sure to read and learn how to activate your account here.

Nifi: how to put File and then reitrive them properly?

Nifi: how to put File and then reitrive them properly?

New Contributor

in custom nifi processo code i use this logic, but it can't help me rename file which is saved in this format ".filename.xml" and then use and reitreive it, what should i change to make this operations?:

Exception is like this:couldn't rename C:\Users\Desktop\try2\nifi-1.3.0\1.conf.xml

<code>final String permissions="x";
                Path tempDotCopyFile = null;
                final Path rootDirPath = get("C://Users//Desktop//try2//nifi-1.3.0//1");
                final Path tempCopyFile = rootDirPath.resolve("."+flowFile.getAttribute(CoreAttributes.FILENAME.key()));
                final Path copyFile = rootDirPath.resolve(flowFile.getAttribute(CoreAttributes.FILENAME.key()));
                final Path dotCopyFile = tempCopyFile;
                //Path finalCopyFile = copyFile;
                String perms = stringPermissions(permissions);
                if (!perms.isEmpty()) {
                    Files.setPosixFilePermissions(dotCopyFile, PosixFilePermissions.fromString(perms));
                }

                //tempDotCopyFile = dotCopyFile;
                Path finalCopyFile = copyFile;
                boolean renamed = false;
                session.exportTo(flowFile,  finalCopyFile, false);
                for (int i = 0; i < 10; i++) { // try rename up to 10 times.
                    if (dotCopyFile.toFile().renameTo(finalCopyFile.toFile())) {
                        renamed = true;
                        break;// rename was successful
                    }
                    Thread.sleep(100L);// try waiting a few ms to let whatever might cause rename failure to resolve
                }

                if (!renamed) {
                    if (Files.exists(dotCopyFile) && dotCopyFile.toFile().delete()) {
                        logger.debug("Deleted dot copy file {}", new Object[]{dotCopyFile});
                    }
                    throw new ProcessException("Could not rename: " + dotCopyFile);
                } else {
                    logger.info("Produced copy of {} at location {}", new Object[]{flowFile, finalCopyFile});
                }
                //session.getProvenanceReporter().send(flowFile, finalCopyFile.toFile().toURI().toString(), stopWatch.getElapsed(TimeUnit.MILLISECONDS));

                Path real=Paths.get( "C://Users//Desktop//try2//nifi-1.3.0//1");
               session.exportTo(flowFile,real,false);