The problem is I use the wrong way to read the stream. Here is the right way.:
import org.apache.commons.io.IOUtils;
Configuration confHadoop = new Configuration();
FileSystem fs = FileSystem.get(confHadoop);
Path file = new Path(fs.getUri().toString() + "/" + fileName);
in = fs.open(file);
byte[] buffer = IOUtils.toByteArray(in);
Then the buffer can be written to sequenceFile by new BytesWritable(buffer)
.
Same when you read from the sequenceFile.