public interface Filer
There are two distinguished locations (subtrees within the file system) where newly created files are placed: one for new source files, and one for new class files. (These might be specified on a tool's command line, for example, using flags such as -s and -d.) Auxiliary files may be created in either location.
During each run of an annotation processing tool, a file with a given pathname may be created only once. If that file already exists before the first attempt to create it, the old contents will be deleted. Any subsequent attempt to create the same file during a run will fail.
| Modifier and Type | Interface and Description |
|---|---|
static class |
Filer.Location
Locations (subtrees within the file system) where new files are created.
|
| Modifier and Type | Method and Description |
|---|---|
java.io.OutputStream |
createBinaryFile(Filer.Location loc,
java.lang.String pkg,
java.io.File relPath)
Creates a new binary file, and returns a stream for writing to it.
|
java.io.OutputStream |
createClassFile(java.lang.String name)
Creates a new class file, and returns a stream for writing to it.
|
java.io.PrintWriter |
createSourceFile(java.lang.String name)
Creates a new source file and returns a writer for it.
|
java.io.PrintWriter |
createTextFile(Filer.Location loc,
java.lang.String pkg,
java.io.File relPath,
java.lang.String charsetName)
Creates a new text file, and returns a writer for it.
|
java.io.PrintWriter createSourceFile(java.lang.String name)
throws java.io.IOException
The charset used to encode the file is determined by the implementation. An annotation processing tool may have an -encoding flag or the like for specifying this. It will typically use the platform's default encoding if none is specified.
name - canonical (fully qualified) name of the principal type
being declared in this filejava.io.IOException - if the file cannot be createdjava.io.OutputStream createClassFile(java.lang.String name)
throws java.io.IOException
name - canonical (fully qualified) name of the type being writtenjava.io.IOException - if the file cannot be createdjava.io.PrintWriter createTextFile(Filer.Location loc, java.lang.String pkg, java.io.File relPath, java.lang.String charsetName) throws java.io.IOException
A charset for
encoding the file may be provided. If none is given, the
charset used to encode source files
(see createSourceFile(String)) will be used.
loc - location of the new filepkg - package relative to which the file should be named,
or the empty string if nonerelPath - final pathname components of the filecharsetName - the name of the charset to use, or null if none
is being explicitly specifiedjava.io.IOException - if the file cannot be createdjava.io.OutputStream createBinaryFile(Filer.Location loc, java.lang.String pkg, java.io.File relPath) throws java.io.IOException
loc - location of the new filepkg - package relative to which the file should be named,
or the empty string if nonerelPath - final pathname components of the filejava.io.IOException - if the file cannot be createdCopyright © 2004, 2013, Oracle and/or its affiliates. All rights reserved