/**
* Searches the data file and prints out the stats of the file.
*/
public static void wordStats() throws Exception
{
File file = new File("words.txt");
Scanner in = new Scanner(new FileInputStream(file));
int words = 1;
String longestWord = new String();
String shortestWord = new String();
String line = in.nextLine();
line = line.trim();
char ch[]= new char[line.length()];
try{
for(int i=0;i<line.length();i++){
ch[i]= line.charAt(i);
if( ((i>0)&&(ch[i]!=' ')&&(ch[i-1]==' ')) || ((ch[0]!=' ')&&(i==0)) ){
words++;
}
}
System.out.println("There are "+words+" words.");
System.out.println("The longest word is "+longestWord+".");
System.out.println("The shortest word is "+shortestWord+".");
}catch(Exception e)
{
System.out.println(e.toString());
}
}
