private void writeIndexToFile() throws IOException {

			if (_occuredIndex == null) {
				return;
			}
			// Maintain 26+10 index files corresponding to 1st character in term (26
			// alphabets + 10 digits)
			String term;
			String indexFileNameOrig, indexFileNameTmp;
			StringBuffer indexData;
			char firstChar;

			// sort the keys
			SortedSet<String> keys = new TreeSet<String>(_occuredIndex.keySet());
			Iterator<String> keyIterator = keys.iterator();

			// loop through all the terms in the index
			while (keyIterator.hasNext()) {
				indexData = new StringBuffer();

				term = keyIterator.next();
				indexData.append(term);
				indexData.append(_termDoclistDelim);
				// append docIds and term count
				Map<Integer, Vector<Integer>> docInfo = _occuredIndex.get(term);
				SortedSet<Integer> docIds = new TreeSet<Integer>(docInfo.keySet());
				for (Integer docId : docIds) {
					indexData.append(docId);
					indexData.append(_docCountDelim);
					// appending till second last element and appending last outside the loop
					// so as to avoid extra comma at the end of the list.
					for(int i = 0; i < docInfo.get(docId).size()-1; i++) {
						indexData.append(docInfo.get(docId).get(i));
						indexData.append(_wordOccurDelim);
					}
					indexData.append(docInfo.get(docId).get(docInfo.get(docId).size()-1));
					indexData.append(_doclistDelim);
				}
				indexData.append("\n");

				firstChar = term.charAt(0);
				indexFileNameOrig = firstChar + ".idx";
				indexFileNameTmp = firstChar + "_tmp.idx";

				// Loop through all subsequent keys where the first character of the
				// term is same as that of the previous term
				while (keyIterator.hasNext()
						&& (term = keyIterator.next()).charAt(0) == firstChar) {
					indexData.append(term);
					indexData.append(_termDoclistDelim);
					// append docIds and term count
					docInfo = _occuredIndex.get(term);
					docIds = new TreeSet<Integer>(docInfo.keySet());
					for (Integer docId : docIds) {
						indexData.append(docId);
						indexData.append(_docCountDelim);
						// appending till second last element and appending last outside the loop
						// so as to avoid extra comma at the end of the list.
						for(int i = 0; i < docInfo.get(docId).size()-1; i++) {
							indexData.append(docInfo.get(docId).get(i));
							indexData.append(_wordOccurDelim);
						}
						indexData.append(docInfo.get(docId).get(docInfo.get(docId).size()-1));
						indexData.append(_doclistDelim);
					}
					indexData.append("\n");
				}

				// write info of all terms with the same first characters to the tmp file
				Utilities.writeToFile(_options._indexPrefix + "/"
						+ indexFileNameTmp, indexData.toString(), false);
				// merge old and new files. e.g. merge a.idx and a_tmp.idx -> a.idx
				mergeIndexFiles(indexFileNameOrig, indexFileNameTmp);
			}
		}