从Java中的字符串在内存中创建一个File对象 [英] Create a File object in memory from a string in Java
问题描述
我有一个接受File作为参数的函数。我不想创建/写入一个新的文件(我没有文件系统的写入权限),以便将我的字符串数据传递给函数。我应该添加字符串数据不存在于一个文件(所以我不能从一个文件中读取我的数据)。
我可以使用Streams并将它们投射到File对象吗?
不;类 File
的实例表示文件系统中的路径。因此,您只能使用该功能与文件。但也许有一个重载需要 InputStream
来代替?
I have a function that accepts File as an argument. I don't want to create/write a new File (I don't have write access to filesystem) in order to pass my string data to the function. I should add that the String data don't exist in a file (so I cannot read my data from a file).
Can I use Streams and "cast" them to File objects?
No; instances of class File
represent a path in a filesystem. Therefore, you can use that function only with a file. But perhaps there is an overload that takes an InputStream
instead?
这篇关于从Java中的字符串在内存中创建一个File对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!