Improve file access codes.

It may have some bugs.
Still difficult to do JUnit...