0

I need help on how to start a Java class.

The class defines a method or methods that first reads in a file then reads its characters one by one. After doing this it is to see how many of those characters form words by looking for things like '.' and ' '. After all that, keep count of how many words and put them on a hashmap.

I know how to use a for loop to look for the ' ', ',', '.' etc. and keeping count of words

But I don't know how to read in a file that reads character by character a file.

My TA said something about the 'put' and 'get' method? no idea what they are :S

Therefore I know how to do pretty much everything except the beginning. sorry I can't show you a method of the second half before knowing how to do the first half.

Any help to get this started .. thanks!

Kitsune
  • 9,101
  • 2
  • 25
  • 24
Om Patel
  • 1
  • 1

1 Answers1

1

A Reader will allow you to read data character at a time (e.g. you could use an InputStreamReader together with a FileInputStream to read from a File)

Also make sure you specify the character encoding of the file you are reading, this ensures correct conversion from bytes to chars.

BufferedReader input = new BufferedReader(new InputStreamReader(new FileInputStream("path/to/file"), "charset e.g. utf-8"));
DaveJohnston
  • 10,031
  • 10
  • 54
  • 83