There is a method that outputs intermediate values:

public void IntermediateResultWrite(Map<File, Integer> hm){ Set<Map.Entry<File, Integer>> set = hm.entrySet(); for (Map.Entry<File, Integer> me : set) { System.out.print(Thread.currentThread().getName() + ":"+me.getKey() + ": "); System.out.println(me.getValue()); } 

I need to write intermediate values ​​to .txt.

  • Add to the question those search queries that did not give you the necessary information. - Yuriy SPb

1 answer 1

 Map<File, Integer> map = new HashMap<>(); map.put(new File("somefile1"), 1); map.put(new File("somefile2"), 2); try ( PrintWriter writer = new PrintWriter(new File("/path/to/output.txt")) ) { for ( Map.Entry<File, Integer> entry : map.entrySet() ) { writer.write(Thread.currentThread().getName() + ":" + entry.getKey() + ": " + entry.getValue() + "\n"); } } catch (Exception e) { e.printStackTrace(); } 

If you need to write to the file which is the key of the map, remove try-with-resource inside the loop.