I have the following piece of code that uses the java 7 features like java.nio.file.Files and java.nio.file.Paths
import java.io.File;
impor
You are right to avoid FileReader
as that always uses the default character encoding for the platform it is running on, which may not be the same as the encoding of the JSON file.
ObjectMapper has an overload of readValue
that can read directly from a File
, there's no need to buffer the content in a temporary byte[]
:
Employee emp = objectMapper.readValue(new File("employee.txt"), Employee.class);