Normally I have been using FileChooser in JavaFX. Super easy to do that. Just call it and it will open a new window where you can select your file. Done!
But FileChooser
does not work on Android and Iphone. I have to choose StorageService
instead
https://docs.gluonhq.com/charm/javadoc/5.0.1/com/gluonhq/charm/down/plugins/StorageService.html
File privateStorage = Services.get(StorageService.class)
.flatMap(StorageService::getPrivateStorage)
.orElseThrow(() -> {
new FileNotFoundException("Could not access private storage.");
});
But the problem here is that it gives an error:
The method orElseThrow(Supplier<? extends X>) in the type Optional<File> is not applicable for the arguments (() -> {})
So how can I solve this?
You can do it like this:
Optional.empty().orElseThrow(FileNotFoundException::new);
or
Optional.empty().orElseThrow(()->new FileNotFoundException("Some exception"));
or
Optional.empty().orElseThrow(() -> {
return new FileNotFoundException("Some exception");
});
Worth to read: When are braces optional in Java 8 lambda syntax?