Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Programmatically determining the cause of IOException?

Tags:

java

file-io

Is there any way to programmatically differentiate between what caused an IOException? For example Java will throw an IOException, if there was an error during writing. How can I tell, if it's something like access violation, if the Disk is out of free space, if someone disconnected the the network drive, or other things?

I can't really parse the Message since, there does not seem to be any standardized message format, Sun (or Oracle now I guess) doesn't seem to have any sort of standardized format.

(I need to use Java to fix a very broken system at work.)

like image 786
UberJumper Avatar asked Jul 29 '10 15:07

UberJumper


1 Answers

Unfortunately Java has no equivalent of .NET's System.Runtime.InteropServices.Marshal.GetHRForException(). You tell what kind of I/O error it was only if the exception is an instance of a subclass, e.g. FileNotFoundException.

like image 113
finnw Avatar answered Sep 24 '22 18:09

finnw