Scanning a directory and listing contents in an HTML file
Files and Paths

Since Java 7, the recommended way of traversing a file system is to rely on the new Path class and associated Files and Paths helper classes.

Furthermore, since you are on Java 8, there is the Files.list(Path) method that lets you iterate through a given directory as a form of Stream&lt;Path&gt;, so that you can leverage on the stream-processing features.

For example, just to pad each entry in the given directory with &lt;li&gt;...&lt;/li&gt;, the following snippet does something similar to your for-loop:

List&lt;String&gt; contents;
try {
    // assuming directoryPath is validated as a directory already
    contents = Files.list(directoryPath)
                    .map(v -&gt; "&lt;li&gt;" + v + "&lt;/li&gt;")
                    .collect(Collectors.toList());
} catch (IOException e) {
    // handle accordingly
}


To write contents out to a file, there's also Files.write(Path, Iterable, OpenOption):

try {
    Files.write(outputPath, contents);
} catch (IOException e) {
    // handle accordingly
}


However, since you need to write the header and 'close' the end of the HTML document, you can rely on the forEach() terminal operation of a Stream:

private static void writeDirectoryFilesToHTML(Path directoryPath, 
                                                Path outputPath) throws IOException {
    try (FileWriter target = new FileWriter(outputPath.toFile());
            BufferedWriter buffered = new BufferedWriter(target);
            PrintWriter writer = new PrintWriter(buffered)) {
        writer.write("&lt;html&gt;\n\t&lt;body&gt;\n\t\t&lt;h1&gt;Contents of "
                        + directoryPath.toRealPath() 
                        + ":&lt;/h1&gt;\n\t\t&lt;ul&gt;\n");
        Files.list(directoryPath)
                .map(v -&gt; "\t\t\t&lt;li&gt; " + v + " &lt;/li&gt;")
                .forEach(writer::println);
        writer.write("\t\t&lt;/ul&gt;\n\t&lt;/body&gt;\n&lt;/html&gt;");
    }
}


Here, writer::println is used as a method reference.

HTML output and OS-dependent newlines

You can also consider using some sort of a HTML output library so that you do not have to manually specify "&lt;html&gt;...&lt;ul&gt;...&lt;/ul&gt;...&lt;/html&gt;" (for example).

You are currently hard-coding your newlines to be \n, so you may want to create a helper method that writes the OS-dependent newlines for you, after every call to write().

Other observations

As you can see from above, it's recommended that your method takes in the output path as well, instead of assuming "output.html".