What happens when I open an IndexWriter, optimize the index, and then close the IndexWriter? Which files will be added or modified?

Otis Gospodnetic

All of the segments are merged into a single new segment file. If the index was empty to begin with, no segments will be created, only the segments file.