Jimfs是一个用于Java7+的内存中的文件系统,实现了java.nio.file抽象文件系统API.
Maven
<dependency> <groupId>com.google.jimfs</groupId> <artifactId>jimfs</artifactId> <version>1.0</version></dependency>示例代码:
import com.google.common.jimfs.Configuration;import com.google.common.jimfs.Jimfs;...// For a simple file system with Unix-style paths and behavior:FileSystem fs = Jimfs.newFileSystem(Configuration.unix());Path foo = fs.getPath("/foo");Files.createDirectory(foo);Path hello = foo.resolve("hello.txt"); // /foo/hello.txtFiles.write(hello, ImmutableList.of("hello world"), StandardCharsets.UTF_8);
评论