[IMPR] use context manager for closing a file

Authored by Xqt on Wed, May 16, 2:39 PM.

Description

[IMPR] use context manager for closing a file

Change-Id: I555dd38142f0651dda6264ee1f7898ac6adba90f