So far I have the following code below. Coding is a new hobby for me and I am below a beginner. I copied and pasted this from stackoverflow in order to read a text file
BufferedReader r = new BufferedReader( new FileReader( "test.txt" ) );
String s = "", line = null;
while ((line = r.readLine()) != null) {
s += line;
}
and then this from a website I found to print one word at a time.
int i; // Position in line, from 0 to line.length() - 1.
char ch; // One of the characters in line.
boolean didCR; // Set to true if the previous output was a carriage return.
System.out.println();
didCR = true;
for ( i = 0; i < s.length(); i++ ) {
ch = s.charAt(i);
if ( Character.isLetter(ch) ) {
System.out.print(ch);
didCR = false;
}
else {
if ( didCR == false ) {
System.out.println();
didCR = true;
}
}
}
System.out.println(); // Make sure there's at least one carriage return at the end.
I would really love to output the text file, one word at a time by whitespace so that characters such as commas and periods are included. Please help!