• Post Reply Bookmark Topic Watch Topic
  • New Topic

checking to see if a file write is successful  RSS feed

 
Subhash L. Sriram
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am writing a program that takes in a file, sorts it, and then writes it back to another file.

What I want to do is, check to see if the file is written successfully, and then display the message "File written successfully" out, because I have no other screen output as of now.

Is there a condition to check to see if it is successful, or would I have to write a separate function.

What I have is:



Thanks in advance
 
Warren Dew
blacksmith
Ranch Hand
Posts: 1332
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you reach the end of your code without an exception being thrown, the file has been sent successfully to the operating system, and probably to the file system.

If you want to double check, you could create a java.io.File object for your file name and call its isFile() method. If you really want to be sure, I suppose you could open the file, read it back in, and check that it's correct, but that might be overkill.
 
Subhash L. Sriram
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your help! I got the answer I was hoping for
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!