构造一个从字节数组读取的java.io.File [英] Construct a java.io.File that reads from a byte array

查看:83
本文介绍了构造一个从字节数组读取的java.io.File的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用一个需要java.io.File作为输入的API,但是我想只向该API发送一个字节数组.有没有一种方法可以创建一个文件对象,该对象将从我的字节数组而不是磁盘读取?

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?

推荐答案

文件不读取任何内容.它代表操作系统(或虚拟文件等)中的文件(或目录)对象.要从中读取内容,您将不得不创建Readers或Streams,API会自行执行.如果API不提供传递Reader或InputStream的方法,那么您很不走运.

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.

这篇关于构造一个从字节数组读取的java.io.File的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆