Java in-memory file structure?

2020-07-10 09:03发布

I need to do a lot of things with resources on the fly: parsing xsd/xml docs, building and compiling java classes, package them into jars ans wars, persist in DB, deploy them as OSGi, etc.

Most of the libraries/API's, which I use, allow to perform all these intermediate tasks in memory, but there are some "special" libraries operating with java.io.File only. And there's nothing left for me but using real temporary files and directories which is not good in Java EE environment.

I believe there must be a library/solution for in-memory file structure having nodes extending java.io.File (as I see it). Please drop in a link to known/similar libraries. Any comments are welcome.

Thanks!

3条回答
做个烂人
2楼-- · 2020-07-10 09:32

One option is to use a RAM disk. Your program will think its using the disk with java.io.File, but it will really be using main memory.

查看更多
Rolldiameter
3楼-- · 2020-07-10 09:36

I do not believe you are going to find what you are looking for. The java.io.File API was not written with the intention of providing a file system abstraction that can be implemented in a variety of ways. While it does expose method for some FS operations (such as delete and mkdir), it doesn't handle the basic read/write I/O. That is left to other classes, such as FileInputStream. This means that from API standpoint, a File object is no more than a path. Nothing is abstracted. You are stuck.

查看更多
等我变得足够好
4楼-- · 2020-07-10 09:37

There is a fine alternative available: https://github.com/google/jimfs

This supports java(7+) in memory filesystem handling and is very easy to use too.

查看更多
登录 后发表回答