how do i get java to count words in a outfile?

import java.io.*;

public class IOLoop

{

public static BufferedReader inFile;

public static PrintWriter outFile;

public static void main(String[] args) throws IOException

{

int lineCount = 0;

int blankCount;

int index;

String inputString;

inFile = new BufferedReader(new FileReader("history.dat"));

outFile = new PrintWriter(new FileWriter("data.out"));

inputString = inFile.readLine();

while (inputString != null)

{

lineCount++;

blankCount = 0;

index = inputString.indexOf(' ');

while (index != -1)

{

blankCount++;

if (inputString.length() != 1)

{

inputString = inputString.substring(index+1,

inputString.length());

index = inputString.indexOf(' ');

}

else index = -1;

}

outFile.println("Line " + lineCount + " contains "

+ blankCount + " blanks.");

inputString = inFile.readLine();

}

outFile.close();

inFile.close();

}

}

i need to edit this to count words instead of blank's , it sounds easy but its really kickin me in the butt, any help would be apprecaited

 
Activity
No one is currently typing a reply...

About this thread

Twistid

5,000+ posts
150.5
Thread starter
Twistid
Joined
Location
in a space out of sound
Start date
Participants
Who Replied
Replies
1
Views
116
Last reply date
Last reply from
Shyne151
IMG_20260506_140749.jpg

74eldiablo

    May 22, 2026
  • 0
  • 0
design.jpeg

WNCTracker

    May 22, 2026
  • 0
  • 0

New threads

Top