diff --git a/src/main/java/org/scijava/io/handle/DataHandleService.java b/src/main/java/org/scijava/io/handle/DataHandleService.java index 97175e4d9..5d4f1a77e 100644 --- a/src/main/java/org/scijava/io/handle/DataHandleService.java +++ b/src/main/java/org/scijava/io/handle/DataHandleService.java @@ -32,6 +32,8 @@ package org.scijava.io.handle; +import java.io.IOException; + import org.scijava.io.IOService; import org.scijava.io.location.Location; import org.scijava.plugin.WrapperService; @@ -63,4 +65,18 @@ default Class> getPluginType() { default Class getType() { return Location.class; } + + /** + * Convenience method to test whether it describes an existing file. + * + * @param location the location to test + * @return The result of {@link DataHandle#exists()} on a newly created handle + * on this location + * @throws IOException + */ + default boolean exists(final Location location) throws IOException { + try (DataHandle handle = create(location)) { + return handle.exists(); + } + } }