Useful Java Snippets for Running Map Reduce in Hadoop

Useful Java Snippets for Running Map Reduce in Hadoop

Delete Existing File

If you need to delete an existing directory before writing over it you can use the following snippet. Note that with hadoop files are not automatically overwriten. However, files and directories are automatically created.

FileSystem fs = FileSystem.get(getConf());
fs.delete(new Path(outputDirectoryPath), true);