In-memory file system in java

I want to create a simple in-memory file system in Java that has one root directory and can create a new subdirectory. In the directory we can create new files, write to them, read from them, delete them and also rename them. Can you give some tips on where to start (simple code or resouce).

+6
source share
3 answers

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

Below are the links below.

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

The link below (and not on the file system) refers to the virtual file system. It talks about some design issues that can help you if you decide to create your own file system.

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

But you can always use already built and tested code. It will be faster and easier to maintain, and you will receive support in the face of errors.

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

https://github.com/google/jimfs

Also view

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

marschall (An in memory for implementing the JSR-203 file system) https://github.com/marschall/memoryfilesystem

+9
source

You can create an In-memory file system in java using the Googles Jimfs and java 7 NIO packages.

Please refer to this link. Here you will get a sample tutorial: create a file system in memory in java

+4
source

Use memoryfilesystem .

Jimfs is mentioned in a previous answer, but the memoryfilesystem handles a lot more.

Usage example:

final FileSystem fs = MemoryFileSystem.newLinux().build("myfs"); final Path dir = fs.getPath("thedir"); Files.createDirectory(dir); 

etc. Use the java.nio.file API to manage the files in this ( File will not work!). See here for more details.

+2
source

Source: https://habr.com/ru/post/987733/


All Articles