Hi everyone currently i am working on an assignment of making an Java program to read all the files present in the path and build up a dictionary of words with frequencies of words occurred in the text files but i am getting errors in the reading of files and i am posting the block of code i have used can any one kindly guide me to do this task please!
The following is the error i am gettingpublic static void build() { BufferedReader br = null; Scanner in = new Scanner(System.in); String path_name=in.nextLine(); System.out.println("I am building an Dictionary from the files present in the path:"+path_name); Path path = Paths.get(path_name); File folder = new File(path_name); File[] listOfFiles = folder.listFiles(); for (int i = 0; i < listOfFiles.length; i++) { if (listOfFiles[i].isFile()) { String files = listOfFiles[i].getName(); if (files.endsWith(".txt") || files.endsWith(".TXT")) { br = new BufferedReader(new FileReader(files)); String s=""; while(br.ready()) { s+=br.readLine()+"\n"; } } } } }
Dictionary.java:78: error: unreported exception FileNotFoundException; must be caught or declared to be thrown
br = new BufferedReader(new FileReader(files));
^
Dictionary.java:80: error: unreported exception IOException; must be caught or declared to be thrown
while(br.ready()) {
^
Dictionary.java:81: error: unreported exception IOException; must be caught or declared to be thrown
s+=br.readLine()+"\n";
^
3 errors