Question: [JAVA] Please find error. This isn't working. ---------------------------------------------------------------------------------------------- import java.io.*; import java.util.*; public class CountWordsFile { @SuppressWarnings(resource) public static void main(String[] args){ String javaprogramming =

[JAVA]

Please find error. This isn't working.

----------------------------------------------------------------------------------------------

import java.io.*;

import java.util.*;

public class CountWordsFile {

@SuppressWarnings("resource")

public static void main(String[] args){

String javaprogramming = args[0];

TreeMapTreeMap=new TreeMap();

try{

Scanner input = new Scanner(new File("testing.txt"));

while (input.hasNext()){

String line=input.nextLine();

String[]words=line.split("[ @!~{}\\[\\]$#^&* \t .,;?'\")(] "); for (int i=0;i

if (words[i].trim().length () >0 && words[i].trim().matches("[A-Z|a-z]+")){

String key =words[i].toLowerCase();

if (TreeMap.get(key)!=null){

int count =TreeMap.get(key);

count++;

TreeMap.put(key,count);

}

else{

TreeMap.put(key, 1);

}

}

}

}

}

catch (Exception ex){

ex.printStackTrace();

}

Set>entrySet=TreeMap.entrySet();

System.out.print(" Total words in the file:");

for (Map.Entryentry: entrySet) System.out.println(entry.getValue()+"\t" +entry.getKey());

}

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!