code: public static File createFile(String filePath) throws IOException {
  
          boolean isDirectory = filePath.endsWith("/") || filePath.endsWith("\\");
  
          String formattedFilePath = formatFilePath(filePath);
  
          File f = new File(formattedFilePath);
  
          if (f.exists()) {
              return f;
          }
  
          if (isDirectory) {
              f.mkdirs();
          } else {
              f.getParentFile().mkdirs();
              f.createNewFile();
          }
          if (f.exists()) {
              f.setExecutable(true, false);
              f.setReadable(true, false);
              f.setWritable(true, false);
              return f;
          }
          throw new IOException("Error creating file: " + f.getAbsolutePath());
      }
docs: Creates a file in the specified path. Creates also any necessary folder
  needed to achieve the file level of nesting.
  
  @param filePath the path of file to create.
  @return the new created file. <code>null</code> if the file can no be
  created.
  @throws IOException if an IO error occurs.