In-memory file system in java

alle3x picture alle3x · May 22, 2015 · Viewed 15.2k times · Source

I want to create a simple in-memory file system in Java, which has one root directory and is able to make new sub directory. In the directory we can make new files, write in them, read from them, delete them and also rename them. Can you please give some advice from where to start (a simple code, or resouce).

Answer

Raj picture Raj · May 22, 2015

A custom file system provider must implement the java.nio.file.spi.FileSystemProvider class. A file system provider is identified by a URI scheme such as file, jar, memory, cd.

These links below provide good starting info

http://docs.oracle.com/javase/7/docs/technotes/guides/io/fsp/filesystemprovider.html

The link below(not about in memory file system) is about virtual file system. It talks about some design issues which could help you in case you decide to create your own file system.

http://www.flipcode.com/archives/Programming_a_Virtual_File_System-Part_I.shtml

But you could always use already built and tested code.This will be faster and easier to maintain and you will receive support in error conditions.

Take a look at jimfs ( An in-memory file system for Java 7+ )

https://github.com/google/jimfs

Also look into

Commons Virtual File System http://commons.apache.org/proper/commons-vfs/

marschall (An in memory implementation of a JSR-203 file system) https://github.com/marschall/memoryfilesystem