This week's book giveaway is in the JavaScript forum.
We're giving away four copies of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js and have Paul Jensen on-line!
See this thread for details.
Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

I/O  RSS feed

 
gurpreetsingh hora
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Will somebody suggest me
while refrring the code below

can somebody suggest me why to use Flush when we are alrady using close in the code?

Class A
{
public static void main(String[]args) throws Exception
{
int i;
FileOutputStream f= new FileOutputStream("A.txt");
ObjectOutputStream b= new ObjectOutputStream(f);

try
{
b.writeObject();
b.Flush();
b.close();
}
Catch(Exception e)
{}
}
}
Now my question is that if we have used close ()method it will close the connection then why to use Flush method()??
pLease consider if there is ant mistake in the code!!!

Cheers
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's not a mistake to call flush here, but it is not necessary. Removing it wouldn't change the program's behavior at all.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!