简体   繁体   中英

Annotation processor: file writing from the process() method

I wrote an annotation processor and i'd like to write some information into a text file. In my class I'm extending the AbstractProcessor and overriding the

public void init(ProcessingEnvironment processingEnv)

and

public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv)

methods.

In the init() method I'm creating a new PrintWriter (eg. this way: writer = new PrintWriter("output.csv", "UTF-8"); )

with which I print some text into a file in the process() method.

The problem is, that (as I use my processor on multiple sources in different packages) the file ( output.csv ) always gets recreated when a new source is being processed (because a new Processor object is created each time). This way only the lastly processed source's information gets into the text file, although I want to acquire information from all of the annotated methods (from different sources) into one text file.

This might help you:

new PrintWriter(new FileOutputStream("output.csv", true));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM