Watching files in Java with WatchService

Java 7 introduced a useful API for watching files on the file system. This feature comes in handy if you need to scan a directory for new files or modified files. The API is event driven, so the system will notify you of certain events such as "new file", "modified file" or "deleted file". The example below demonstrates the key [...]

By |2014-04-22T21:39:15-04:00April 22, 2014|How-To, Java|Comments Off on Watching files in Java with WatchService

Iterating a HashMap

Here is a quick example that shows how to iterate over a HashMap. You have the option of using the map key set or the map entry set.   [code] import java.util.HashMap; import java.util.Map; import java.util.Set; public class HashDemo { public static void main(String[] args) { Map<String, String> theMap = new HashMap<String, String>(); theMap.put("alfa", "john"); theMap.put("beta", "mary"); theMap.put("code", "susan"); // [...]

By |2014-04-04T08:05:15-04:00April 4, 2014|Collections API, How-To, Java|Comments Off on Iterating a HashMap
Go to Top