If I'm using Java and I have a String
of a Data URI, is it possible to create a File
from that String
value?
For example, here's what I'm currently trying to do:
//A data URI representing a txt file
String dataUri = "data:text/plain;base64,VGVzdGluZy4=";
//This line works fine. The URI is created
URI testURI = new URI(dataUri);
//This line throws this exception: java.lang.IllegalArgumentException: URI is not hierarchical
File test = new File(testURI);
I've looked at posts related to the exception (Why is my URI not hierarchical?, and Java Jar file: use resource errors: URI is not hierarchical), but neither of these original questions are trying to do what I'm trying to do. Also, I understand that the issue is because the URI
is not in this form C:\path\to\a\file.example
(hierarchical). This is clearly stated in the documentation. So I understand that this is not a proper way to go about what I'm trying to do, I'm just not sure what else to try.
Is it possible to convert a data URI to a File
(or perhaps a similar class) in Java?