Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Boone # 44

 
Stewart Henry
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The Question is:

The answer is given as e, and indeed when I compile and run this code on NT that is what happens. However, I think this code is getting away cheap because it never calls out.close().
I remembered from my C/UNIX days that you always had to call flush() then close() before the program terminated otherwise you got an empty file, partial contents, or plain junk. I think that d might also be an appropriate answer depending on the JVM and what the operating system is doing at the time when you run this code.
Is java different then C in respect calling close()?
 
Jyotsna Umesh
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Stewart,
Your question is interesting. Its always better to close the any open files, it cleans up the memory resources but even id you don't the randon access file will bot be blank, it will show you the right data that you have added.
But its healthy practise to close any open file when you are through with the task.
Jyotsna
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic