added check for file type. raise exception if not text.