I would strongly advise using InputStreamReader instead of FileReader, but explicitly specifying the character encoding. That's really the biggest benefit of using InputStreamReader (and the lack of ability to specify an encoding for FileReader is a major hole in the API, IMO).
I'd also remove the "layer" using DataInputStream - just pass the FileInputStream to the InputStreamReader constructor.
Alternatively, consider using some of the many convenience methods in Guava which can make this sort of thing much simpler. For example:
File file = new File("C:\\testnew\\out.text"); List<String> lines = Files.readLines(file, Charsets.UTF_8));Read full article from java - Choosing between FileReader and InputStreamReader - Stack Overflow
No comments:
Post a Comment