java java中的内存文件系统

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/30394737/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-02 17:02:40  来源:igfitidea点击:

In-memory file system in java

javafilesystemsimplementation

提问by alle3x

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).

我想在 Java 中创建一个简单的内存文件系统,它有一个根目录并且能够创建新的子目录。在目录中,我们可以创建新文件、写入它们、读取它们、删除它们以及重命名它们。你能从哪里开始给出一些建议吗(一个简单的代码或资源)。

回答by Raj

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.

自定义文件系统提供程序必须实现 java.nio.file.spi.FileSystemProvider 类。文件系统提供程序由 URI 方案标识,例如文件、jar、内存、cd。

These links below provide good starting info

下面的这些链接提供了很好的入门信息

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

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

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+ )

看看 jimfs(Java 7+ 的内存文件系统)

https://github.com/google/jimfs

https://github.com/google/jimfs

Also look into

也看看

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

公共虚拟文件系统http://commons.apache.org/proper/commons-vfs/

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

marschall(JSR-203 文件系统的内存实现)https://github.com/marschall/memoryfilesystem

回答by Reena Upadhyay

You can create In-memory file system in java using Google's Jimfs and java 7 NIO package.

您可以使用 Google 的 Jimfs 和 java 7 NIO 包在 java 中创建内存文件系统。

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

请参考这个链接。在这里你会得到一个示例教程: 在java中创建内存文件系统

回答by fge

Use memoryfilesystem.

使用内存文件系统

Jimfs has been mentioned in a previous answer, but memoryfilesystem handles much more.

Jimfs 在之前的回答中已经提到过,但是 memoryfilesystem 处理的更多。

Example usage:

用法示例:

final FileSystem fs = MemoryFileSystem.newLinux().build("myfs");

final Path dir = fs.getPath("thedir");

Files.createDirectory(dir);

etc etc. Use the java.nio.file API to manipulate files in this (Filewon't work!). See herefor more details.

等等等等。使用 java.nio.file API 来操作这里的文件(File不会工作!)。请参阅此处了解更多详情。