You need to do google searches and look other places before asking questions, we generally handle fixing codes with small problems or errors. However, since people may come looking now that google can find this page...
First to read a file, you'll need a few Streams - things that do input/output with data.
File file = new File("C:\\MyFile.txt");
FileInputStream fis = new FileInputStream(file);
BufferedInputStream bis = new BufferedInputStream(fis);
DataInputStream dis = new DataInputStream(bis);
You'll be using the one on the end to access your data. If the file contains multiple lines, you'll want to use a loop to get them all:
while (dis.available() != 0) { // Tests for more lines
String s = dis.readLine(); // Get the line
Now you split the lines into different strings using the method sushain97 showed you:
String[] sParts = s.split(" "); // Splits the strings into an array using the 'SPACE' as a reference
We need an array of integers for all the letters. The length will be the longest string.
int longestLength = 1; // The longest length of word
for (String strx : sParts) { // Go through each sPart, the next one is called strx
if (longestLength < strx.length()) // If it's got a longer length than the current record
longestLength = strx.length(); // Set a new record
}
int[] counts = new int[longestLength + 1]; // Make the array with the length needed; +1 since arrays are 0-based
Loop through all the strings and add 1 to the corresponding array number.
for(String str : strings)
counts[str.length()] += 1; // Add one to the number of words that length has
And output it:
for(int i = 1; i < counts.length; i++) // We use this type of loop since we need the length
System.out.println(i + " letter words: " + counts[i]);
} // Close that while loop from before
In the future, please do as I suggested, but I hope this helps all googlers coming here for information. :)