Construct a java.io.File that reads from a byte array

后端 未结 4 558
失恋的感觉
失恋的感觉 2021-01-20 05:49

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

4条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-20 06:19

    Java works with InputStream (or OutpusStream) approach. Using a java.io.File already enforces too much, then a File class is not anything on which you can read or write: it just represents an entry in a file system (from which you can then, but just then, obtain its associated input and output streams).

    So you should have a method which accepts a generic InputStream. If the API just supports a File object then it's clearly poorly designed (or you are trying to use them in a non allowed way).

提交回复
热议问题