12

I read on oracle that it is possible to create a custom FileSystem, but I can't really find much documentation on creating one. Could anyone link me to somewhere I can learn more about custom FileSystems?

Where I read about this: http://docs.oracle.com/javase/7/docs/technotes/guides/io/fsp/filesystemprovider.html

5
  • 1
    The link you provided contains the information on how to implement custom file system. What else do you need? Commented Apr 9, 2014 at 14:50
  • How to actually create it. Maybe an example? I couldn't really find enough info to go on to actually create one. Commented Apr 9, 2014 at 14:52
  • 1
    I think OpenJDK contains the source of the Zip File System Provider somewhere, if you would like to look at an example. Commented Apr 9, 2014 at 14:54
  • The link you provided contains a reference to the ZipFileSystemProvider as an example of a custom file system provider. I think you should really read that document, especially if you yourself gave a link to it. Commented Apr 9, 2014 at 14:56
  • check under your jdk installation for demo/nio/zipfs/src.zip as stated in the link you provided. You can also find it here Commented Dec 19, 2014 at 14:09

3 Answers 3

16

A (Real) Simple Example

A very simple Java FileSystem to use as an example is nodet/githubfs. There are only a few classes and it will give you the flavor of how to implement a basic file system. The primary classes are:

Note that this file system does not implement all operations (which is part of the reason it is good as a high level example).

Experiment!

To experiment with using a custom FileSystem without any coding, a handy project is puniverse/javafs. It allows you to mount it as a FUSE and interact with it from a terminal. Setup is quite easy:

import co.paralleluniverse.javafs.JavaFS;
...
// Need to mkdir /tmp/mnt first
JavaFS.mount(fileSystem, Paths.get("/tmp/mnt"));
Thread.sleep(Long.MAX_VALUE);
Sign up to request clarification or add additional context in comments.

1 Comment

Is this approach similar to AndrewFileSystem? I have a work in some months and can't really know where to start. Thanks in beforehand.
9

Google opensourced a completely in-memory filesystem implementation called JimFS: https://github.com/google/jimfs

Comments

3

I know this is an old question but many people still want the actual answer, which is not here. The problem is that the documentation by Oracle (Sun), listed by the OP is missing critical information. What adds to the confusion is that the "demo" referenced by the doc is packaged in a confusing way. There is a Demo.java source file and src.zip and a zipfs.jar. The Demo.java is NOT a FileSystemProvider. Its a custom FileSystem. For it to work you have to add the zipfs.jar to the "extensions" folder of your JRE/JDK, so that when the Demo.getZipFSProvider() method is called, it will find the custom FileSystemProvider which returns the custom FileSystem. If you look in the src.zip you will find the code for the provider. If the Java documentation had been properly written this question would not have come up. Its confusing. Even the readme file in the demo makes no mention of the provider. Sad.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.