I'm using an API that requires a java.io.File as input, but I'd like to just send the API a byte array. Is there a way to create a File object that will read from my byte array rather than from disk?
A File
does not read anything. It represents a file (or directory) object in the Operating System (or virtual file, etc.). To read from it, you wil have to create Readers or Streams, which the API will do on its own. If the API does not provide methods to pass in a Reader or InputStream, you are out of luck.
You could open a temporary file: open temp file in java
Then if take your byte[] and write it all to the temporary file through some OutputStream/Writer you should have what you need. Then you can pass the file without creating it on disk.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With