Can some one redo this code without the try-catch and an alternative to using Entry when printing the treemap package part2; import java.io.*; import java.util.Map.Entry; import java.util.*; public class frequencyOfWords { public static void main(String[] args) { long totalTime = 0; long startTime = System.nanoTime(); TreeMap map = new TreeMap<>(); for(int i=1; i <= 77; i++){ startTime = System.nanoTime(); Scanner sc = new Scanner(System.in); File file = new File("c:/Users/tvazq/IdeaProjects/hw2/resources/" + i +".okpuncs"); Scanner reader; String line = ""; try { reader = new Scanner(file); while(reader.hasNextLine()){ line = reader.nextLine(); String words[] = line.split(" "); for(String s : words){ if(map.containsKey(s)){ map.put(s, map.get(s)+1); }else{ map.put(s, 1); } } } } catch (FileNotFoundException e) { System.out.println("file not found"); } sc.close(); totalTime+= (System.nanoTime()-startTime); } System.out.printf("%-20s%-20s\n","Word","Frequency"); for(Entry entry : map.entrySet()) //printing map System.out.printf("%-20s%-20d\n",entry.getKey(),entry.getValue()); System.out.println("Total time took : " + totalTime); } }.