Creating a File from byte array

前端 未结 3 1480
你的背包
你的背包 2020-12-19 04:52

So - I\'ve got a third party library that needs a File as input. I\'ve got a byte array.

I don\'t want to write the bytes to disk .. I\'d

3条回答
  •  离开以前
    2020-12-19 05:33

    There's one possibility, but it's a real long-shot.

    If the API uses new FileReader(file) or new FileInputStream(file) then you're hosed, but...

    If it converts the file to a URL or URI (using toURL() or toURI()) then, since File is not final, you can pass in a subclass of File in which you control the construction of the URL/URI and, more importantly, the handler.

    But the chances are VERY slim!

提交回复
热议问题