title: Lucene indexwriter destination folder
body: <p>I'm working on a small lucene project, where i have to index a bunch of text files. so far i've managed to create the index, i think. the code runs and i get a bunch of files called 0_.<em>*</em> fdt/fdx/fnm and more.</p>
  
  <p>what i want to know is, can i pick a destination folder, for the index to be created in? </p>
  
  <p>i'm following this <a href="http://www.avajava.com/tutorials/lessons/how-do-i-use-lucene-to-index-and-search-text-files.html" rel="nofollow">Guide</a> and i define a index folder, and a files to index folder, but i can't find any parameters in the indexwriter constructor, that could achieve this.</p>
  
  <p>here's my code for creating the index</p>
  
  <pre><code>public static void createIndex() throws CorruptIndexException, LockObtainFailedException, IOException {
      File[] files = FILES_TO_INDEX_DIRECTORY.listFiles();
      Analyzer analyzer = new StandardAnalyzer(Version.LUCENE_33);
      SimpleFSDirectory d = new SimpleFSDirectory(FILES_TO_INDEX_DIRECTORY);
      IndexWriter indexWriter = new IndexWriter(d, analyzer, IndexWriter.MaxFieldLength.LIMITED);
  
      for (File file : files) {
          Document document = new Document();
  
          String path = file.getCanonicalPath();
          byte[] bytes = path.getBytes();
          document.add(new Field(FIELD_PATH, bytes));
  
          Reader reader = new FileReader(file);
          document.add(new Field(FIELD_CONTENTS, reader));
  
          indexWriter.addDocument(document);
      }
      indexWriter.optimize();
      indexWriter.close();
  }
  </code></pre>
  
  <p>and i'm using type File instead of string for the directories</p>
  
  <pre><code>public static File FILES_TO_INDEX_DIRECTORY = new File("C:\\Users\\k\\Dropbox\\Public\\afgansprojekt\\RouteLogger\\Lucene\\FilesToIndex");
  public static final File INDEX_DIRECTORY = new File("C:\\Users\\k\\Dropbox\\Public\\afgansprojekt\\RouteLogger\\Lucene\\Index");
  </code></pre>