Common usage of file IO in java