title: Java: Can't override postVisitDirectory
body: <p>I wrote a single-purpose program to walk through a directory and print all the directory and file names to a file, but the compiler throws an error which says "dirWalkerPrinter\DirWalkerPrinter.java:52: error: method does not override or implement a method from a supertype". The code of the program is as follows:</p>
  
  <pre><code>/**
   * This program walks a directory tree
   * and prints out the directory name and the file names under it.
   * @author Michael Mei
   * @version 1.0 22-03-2020
   */
  
  package walkDirectory;
  
  import java.io.*;
  import java.nio.file.*;
  import java.nio.file.attribute.*;
  import static java.nio.file.FileVisitResult.*;
  import static java.nio.file.FileVisitOption.*;
  import java.nio.charset.StandardCharsets;
  import java.util.*;
  
  public class DirWalkerPrinter extends SimpleFileVisitor&lt;Path&gt; {
      private Path outPath;
      private Writer out;
      private int fileCount;
      private int dirCount;
  
      DirWalkerPrinter (Path outPath) throws IOException {
          this.outPath = outPath;
          out = Files.newBufferedWriter(outPath, StandardCharsets.UTF_16, StandardOpenOption.WRITE);
      }
  
      public int getFileCount () {
          return fileCount;
      }
  
      public int getDirCount () {
          return dirCount;
      } 
  
      public void writeResults(Path p) throws IOException {
          out.write(p.toString());
          out.write("\n");
      }
  
      public void done () throws IOException {
          out.write(fileCount + " of files found in " + dirCount);
      }
  
      @Override
      public FileVisitResult visitFile (Path file, BasicFileAttributes attrs) throws IOException {
          writeResults(file.getFileName());
          fileCount++;
          return CONTINUE;
      }
      @Override  // Error message points to this line
      public FileVisitResult postVisitDirectory (Path dir, BasicFileAttributes attrs) throws IOException {
          writeResults(dir);
          dirCount++;
          return CONTINUE;
      }
      @Override
      public FileVisitResult visitFileFailed (Path file, IOException e) {
          System.err.println(e);
          return CONTINUE;
      }
  
      public static void main(String[] args) throws IOException {
          if (args.length &lt; 2) {
          System.err.println("java DirWalkerPrinter source-path destination-file");
          System.exit(-1);
      }
          Path startingDir = Paths.get(args[0]);
          Path writeToDir = Paths.get(args[1]);
          DirWalkerPrinter dirWalkerPrinter = new DirWalkerPrinter(writeToDir);
          Files.walkFileTree(startingDir, dirWalkerPrinter);
          dirWalkerPrinter.done();
          int fileCount = dirWalkerPrinter.getFileCount();
          int dirCount = dirWalkerPrinter.getDirCount();
          System.out.println(fileCount + " of files found in " + dirCount);
      }
  }
  </code></pre>
  
  <p>Thank you for your help.</p>