0

I am making a small project there is a one module, which is KYC update and In this module i am save AadharCard,PAN Card and Other documents in Folder.So I am using java IO and try to create directory which name is Document and i want to create a sub-directory with user name and for create unique a also append username,id concat.I write a code but the sub-directory didn't crate. My code is

String uploadPath = context.getRealPath("") + "assets" + File.separator + "Document" + File.separator
            + userPojo.getFirstName();
    File file = new File(uploadPath);

    try {
        if (!file.exists()) {
            file.mkdirs();
            logger.debug("Make Dir");
        }

and I also try this

File file = new File(dir, userPojo.getUserName());

    if (!file.exists()) {
        file.mkdirs();
        logger.debug("Make Dir");
    }
Ravi Jangid
  • 291
  • 1
  • 4
  • 15
  • [This old answer](https://stackoverflow.com/a/17748131/243245) suggests you check that you `canWrite()` the existing folder where you're trying to create these. – Rup May 31 '18 at 07:07
  • @Rup Actually I try to use but its not created,can u see my a simple example of code – Ravi Jangid May 31 '18 at 08:53

1 Answers1

0

I search and i solve my problem.So i want to give solution if anyone face this type of problem

File file = new File(uploadPath);
    File file2 = new File(uploadPath, dataPojo.getFirstName()));
    if (!file.exists()) {
        file.mkdirs();
        logger.debug(file.getAbsolutePath());
    }
    if (!file2.exists()) {
        file2.mkdirs();
        logger.debug(file.getAbsolutePath());
    }
Ravi Jangid
  • 291
  • 1
  • 4
  • 15