Tony Stark Tony Stark - 2 months ago 18
Java Question

java class FileSystem & FileSystems, what is the difference between them? When to use one over the other?

I'm new to Java and is trying to learn the concept of IO. I have encountered two Java classes that are very similar, FileSystem & FileSystems. Could someone please tell me what is the difference between them? When to use one over the other? Thanks in advance for any help!

Answer

FileSystems is an utility class/factory that is only used to get instances of FileSystem. Refer to the class documentation for the methods in the FileSystems class.

Basically, you will never use FileSystems except when you want to get an instance of FileSystem. For all other use cases, yo uwould only want to use FileSystem.

Comments