Home » apache » Page 4

Tag Archives: apache

Set content to a file

In this example we shall show you how to set the content to a File. We will make use of the org.apache.commons.io.FileUtils class, that provides file manipulation utilities. To set the content to a File one should perform the following steps: Create a new File by converting the pathname string of the file into an abstract pathname. Create a String ...

Read More »

Get content of a File

With this example we are going to demonstrate how to get the content of a File. We will make use of the org.apache.commons.io.FileUtils class, that provides file manipulation utilities. In short, to get the content of a File you should: Create a new File by converting the pathname string of the file into an abstract pathname. Use readFileToString(File file) API ...

Read More »

touch file using apache commons io example

This is an example of how to touch a file. We will make use of the org.apache.commons.io.FileUtils class, that provides file manipulation utilities. Touching a file implies that you should: Create a new File by converting the pathname string of the file into an abstract pathname. Use lastModified() API method of File that returns the time that the file denoted ...

Read More »

Search Lucene Index

package com.javacodegeeks.lucene; import java.io.File; import org.apache.lucene.analysis.SimpleAnalyzer; import org.apache.lucene.document.Document; import org.apache.lucene.queryParser.QueryParser; import org.apache.lucene.search.IndexSearcher; import org.apache.lucene.search.Query; import org.apache.lucene.search.ScoreDoc; import org.apache.lucene.search.TopDocs; import org.apache.lucene.store.Directory; import org.apache.lucene.store.FSDirectory; import org.apache.lucene.util.Version; public class SimpleSearcher { public static void main(String[] args) throws Exception { File indexDir = new File("c:/index/"); String query = "lucene"; int hits = 100; SimpleSearcher searcher = new SimpleSearcher(); searcher.searchIndex(indexDir, query, hits); } private void ...

Read More »

Create Lucene Index

package com.javacodegeeks.lucene; import java.io.File; import java.io.FileReader; import java.io.IOException; import org.apache.lucene.analysis.SimpleAnalyzer; import org.apache.lucene.document.Document; import org.apache.lucene.document.Field; import org.apache.lucene.index.IndexWriter; import org.apache.lucene.store.FSDirectory; public class SimpleFileIndexer { public static void main(String[] args) throws Exception { File indexDir = new File("C:/index/"); File dataDir = new File("C:/programs/eclipse/workspace/"); String suffix = "java"; SimpleFileIndexer indexer = new SimpleFileIndexer(); int numIndex = indexer.index(indexDir, dataDir, suffix); System.out.println("Total files indexed " + ...

Read More »

Did you mean feature with Apache Lucene Spell-Checker

package com.javacodegeeks.lucene.spellcheck; import java.io.File; import org.apache.lucene.search.spell.PlainTextDictionary; import org.apache.lucene.search.spell.SpellChecker; import org.apache.lucene.store.Directory; import org.apache.lucene.store.FSDirectory; public class SimpleSuggestionService { public static void main(String[] args) throws Exception { File dir = new File("c:/spellchecker/"); Directory directory = FSDirectory.open(dir); SpellChecker spellChecker = new SpellChecker(directory); spellChecker.indexDictionary( new PlainTextDictionary(new File("c:/fulldictionary00.txt"))); String wordForSuggestions = "hwllo"; int suggestionsNumber = 5; String[] suggestions = spellChecker. suggestSimilar(wordForSuggestions, suggestionsNumber); if (suggestions!=null && suggestions.length>0) ...

Read More »