java.io.File and java.nio.file.Path .
A common way to obtain an instance of this class is using
getStandardFileManager, for example:
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();This file manager creates file objects representing regular files, zip file entries, or entries in similar file system based containers. Any file object returned from a file manager implementing this interface must observe the following behavior:DiagnosticCollector<JavaFileObject>diagnostics = newDiagnosticCollector<JavaFileObject>(); StandardJavaFileManager fm = compiler.getStandardFileManager(diagnostics, null, null);
FileObject#delete()
is equivalent to File#delete(),
FileObject#getLastModified()
is equivalent to File#lastModified(),
FileObject#getCharContent(boolean),
FileObject#openInputStream(), and
FileObject#openReader(boolean)
must succeed if the following would succeed (ignoring
encoding issues):
new FileInputStream(new File(fileObject.toUri()))
FileObject#openOutputStream(), and
FileObject#openWriter() must
succeed if the following would succeed (ignoring encoding
issues):
new FileOutputStream(new File(fileObject.toUri()))
FileObject#toUri()
file:///C:/Documents%20and%20Settings/UncleBob/BobsApp/Test.java
jar:///C:/Documents%20and%20Settings/UncleBob/lib/vendorA.jar!/com/vendora/LibraryClass.class
file:BobsApp/Test.java (the file name is relative
and depend on the current directory)
jar:lib/vendorA.jar!/com/vendora/LibraryClass.class
(the first half of the path depends on the current directory,
whereas the component after ! is legal)
Test.java (this URI depends on the current
directory and does not have a schema)
jar:///C:/Documents%20and%20Settings/UncleBob/BobsApp/../lib/vendorA.jar!com/vendora/LibraryClass.class
(the path is not normalized)
All implementations of this interface must support Path objects representing files in the default file system. It is recommended that implementations should support Path objects from any filesystem.
API Note
Some methods on this interface take a Collection<? extends Path>
instead of Iterable<? extends Path>.
This is to prevent the possibility of accidentally calling the method
with a single Path as such an argument, because although
Path implements Iterable<Path>, it would almost never be
correct to call these methods with a single Path and have it be treated as
an Iterable of its components.
| Modifier and Type | Class and Description |
|---|---|
| public static interface | StandardJavaFileManager.
Factory to create |
| Modifier and Type | Method and Description |
|---|---|
| private static <T> Collection | |
| private static Iterable | |
| public default Path | Returns: a path representing the same underlying file system artifacta file object file)Returns the path, if any, underlying this file object (optional operation). |
| private static Iterable | |
| public Iterable | Returns: a list of file objectsan array of files files)Returns file objects representing the given files. |
| public default Iterable | Returns: a list of file objectsan array of paths paths)Returns file objects representing the given paths. |
| public Iterable | Returns: a list of file objectsa list of file names names)Returns file objects representing the given file names. |
| public Iterable | Returns: a list of file objectsa list of files files)Returns file objects representing the given files. |
| public default Iterable | Returns: a list of file objectsa list of paths paths)Returns file objects representing the given paths. |
| public default Iterable | Returns: a list of file objectsa list of paths paths)
Deprecated
since 13. use
getJavaFileObjectsFromPaths(Collection) instead,
to prevent the possibility of accidentally calling the method with a
single Path as such an argument.
Returns file objects representing the given paths. |
| public Iterable | Returns: a list of file objectsa list of file names names)Returns file objects representing the given file names. |
| public Iterable | Returns: a list of files ornull if this location has no
associated search patha location locationReturns the search path associated with the given location. |
| public default Iterable | Returns: a list of paths ornull if this location has no
associated search patha location locationReturns the search path associated with the given location. |
| public boolean | Returns: true if the given file objects represent the same canonical file, zip file entry or path; false otherwisea file object a, FileObject a file object b)Redeclares javax. Compares two file objects and return true if they represent the same canonical file, zip file entry, or entry in any file system based container. |
| public void | setLocation(JavaFileManager.
a location location,a list of files, if files)null use the default
search path for this locationAssociates the given search path with the given location. |
| public default void | setLocationForModule(JavaFileManager.
the location location,the name of the module moduleName, Collection<? extends Path> the search path to associate with the location and module. paths)Associates the given search path with the given module and location, which must be a module-oriented or output location. |
| public default void | setLocationFromPaths(JavaFileManager.
a location location,a list of paths, if paths)null use the default
search path for this locationAssociates the given search path with the given location. |
| public default void | setPathFactory(StandardJavaFileManager.
the factory fSpecify a factory that can be used to generate a path from a string, or series of strings. |
| asCollection | back to summary |
|---|---|
| private static <T> Collection | |
| asFiles | back to summary |
|---|---|
| private static Iterable | |
| asPath | back to summary |
|---|---|
| public default Path asPath(FileObject file) Returns the path, if any, underlying this file object (optional operation).
File objects derived from a Implementation Specification The default implementation throws
| |
| asPaths | back to summary |
|---|---|
| private static Iterable | |
| getJavaFileObjects | back to summary |
|---|---|
| public Iterable Returns file objects representing the given files. Convenience method equivalent to: getJavaFileObjectsFromFiles(Arrays.asList(files))
| |
| getJavaFileObjects | back to summary |
|---|---|
| public default Iterable Returns file objects representing the given paths. Convenience method equivalent to: getJavaFileObjectsFromPaths(Arrays.asList(paths)) Implementation Specification The default implementation will only throw
| |
| getJavaFileObjects | back to summary |
|---|---|
| public Iterable Returns file objects representing the given file names. Convenience method equivalent to: getJavaFileObjectsFromStrings(Arrays.asList(names))
| |
| getJavaFileObjectsFromFiles | back to summary |
|---|---|
| public Iterable Returns file objects representing the given files.
| |
| getJavaFileObjectsFromPaths | back to summary |
|---|---|
| public default Iterable Returns file objects representing the given paths. Implementation Specification The default implementation lazily converts each path to a file and calls
| |
| getJavaFileObjectsFromPaths | back to summary |
|---|---|
| public default Iterable Deprecated since 13. use Returns file objects representing the given paths. Implementation Specification The default implementation lazily converts each path to a file and calls
| |
| getJavaFileObjectsFromStrings | back to summary |
|---|---|
| public Iterable Returns file objects representing the given file names.
| |
| getLocation | back to summary |
|---|---|
| public Iterable Returns the search path associated with the given location.
| |
| getLocationAsPaths | back to summary |
|---|---|
| public default Iterable Returns the search path associated with the given location. Implementation Specification The default implementation calls
| |
| isSameFile | back to summary |
|---|---|
| public boolean isSameFile(FileObject a, FileObject b) Redeclares javax. Compares two file objects and return true if they represent the same canonical file, zip file entry, or entry in any file system based container.
| |
| setLocation | back to summary |
|---|---|
| public void setLocation(JavaFileManager. Associates the given search path with the given location. Any previous value will be discarded. If the location is a module-oriented or output location, any module-specific associations set up by setLocationForModule will be cancelled.
| |
| setLocationForModule | back to summary |
|---|---|
| public default void setLocationForModule(JavaFileManager. Associates the given search path with the given module and location, which must be a module-oriented or output location. Any previous value will be discarded. This overrides any default association derived from the search path associated with the location itself. All such module-specific associations will be cancelled if a new search path is associated with the location by calling setLocation or setLocationFromPaths. Implementation Specification The default implementation throws
| |
| setLocationFromPaths | back to summary |
|---|---|
| public default void setLocationFromPaths(JavaFileManager. Associates the given search path with the given location. Any previous value will be discarded. If the location is a module-oriented or output location, any module-specific associations set up by setLocationForModule will be cancelled. Implementation Specification The default implementation lazily converts each path to a file and calls
| |
| setPathFactory | back to summary |
|---|---|
| public default void setPathFactory(StandardJavaFileManager. Specify a factory that can be used to generate a path from a string, or series of strings.
If this method is not called, a factory whose Implementation Specification The default implementation of this method ignores the factory that is provided.
| |
Path objects from strings.
| Modifier and Type | Method and Description |
|---|---|
| public Path |
| getPath | back to summary |
|---|---|
| public Path getPath(String first, String... more) Converts a path string, or a sequence of strings that when joined form a path string, to a Path. | |