I understand the above program but my problem is reading from
Ms-word(.doc file or .docx file) and writing result to console gives
How can I read from .doc file and write content to console correctly??
Those are structured file formats which contain much else besides the plain text. You need to use a library like Apache POI (which can extract the plain text, and also provides an API to get at the structured content).