code: public static FileWriter createFile(String name, String outDir) throws IOException
     {
        File path = new File(outDir);
        if (!path.exists())
        {
           if (!path.mkdirs())
              throw new IOException("outdir can't be created");
        }
  
        File file = new File(path.getAbsolutePath() + File.separatorChar + name);
  
        if (file.exists())
        {
           if (!file.delete())
              throw new IOException("there is exist file, please check");
        }
  
        return new FileWriter(file);
     }
docs: Create file
  
  @param name   The name of the class
  @param outDir output directory
  @return The file
  @throws IOException Thrown if an error occurs