jnovacho
jnovacho

Reputation: 2903

How to handle failed download file in Java

I'm using following snippet to download file from internet: How to download and save a file from Internet using Java?

The problem is, that the connection is highly unreliable, so sometimes the file is not download whole.

I there any standard way to get rid of the corrupted file? My program is used as data miner, so I don't care about the particular file, I only need that all downloaded files are correct.

Obviously I thought of handling the IOException by calling File#delete method, but I was wondering if there is any automatic way to do it?

Upvotes: 0

Views: 540

Answers (1)

peter.petrov
peter.petrov

Reputation: 39477

There is no automatic way, it is up to the application logic.

If your file fails you may decide to delete it, and then schedule another attempt to download it either immediately (which probably doesn't make much sense), or in a few mins, or when some event occurs (say an event saying "the connection is now up again").

Upvotes: 2

Related Questions