Skip to Main Content

Cant resolve syntax error.

2801625Apr 29 2015 — edited Apr 30 2015

In the current program I am trying to read multiple text files from a folder. I keep getting the following syntax error

"Syntax error on token ";", { expected after this token". I highlighted the line where im getting this error in red.

import java.io.*;

import java.util.*;

public class CacheData {

  // Directory path here

    String path = "C:\\myfiles\\*.txt";

    String files;

    File folder = new File(path);

    File[] listOfFiles = folder.listFiles();

    for (int i = 0; i < listOfFiles.length; i++)

    {

        if (listOfFiles[i].isFile())

        {

            files = listOfFiles[i].getName();

            if (files.endsWith(".txt") || files.endsWith(".TXT"))

            {

                System.out.println(files);

                TreeMap<String, Integer> frequencyMap = new TreeMap<String, Integer>();

                String currentLine="";

                File textFile = new File(files);

                try {

                    BufferedReader br = new BufferedReader(new FileReader(textFile));

                    while ((currentLine = br.readLine()) != null) {

                        currentLine = currentLine.toLowerCase();

                        StringTokenizer parser = new StringTokenizer(currentLine, " \t\n\r\f.,;:!?'");

                        while (parser.hasMoreTokens()) {

                            String currentWord = parser.nextToken();

                            Integer frequency = frequencyMap.get(currentWord);

                            if (frequency == null) {

                                frequency = 0;

                            }

                            frequencyMap.put(currentWord, frequency + 1);

                        }

                    }

                    br.close();

                } catch (FileNotFoundException e) {

                   

                } catch (IOException e) {

                    // TODO Auto-generated catch block

                  

                }

              

            }

        }

      }

    }

}

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked due to inactivity on May 28 2015
Added on Apr 29 2015
3 comments
885 views