Sniplet of ReadFileForRegex.java
public class ReadFileForRegex {
//Converts the contents of a file into a CharSequence
// suitable for use by the regex package.
public CharSequence fromFile(String filename) throws IOException {
FileInputStream fis = new FileInputStream(filename);
FileChannel fc = fis.getChannel();
// Create a read-only CharBuffer on the file
ByteBuffer bbuf = fc.map(FileChannel.MapMode.READ_ONLY, 0, (int)fc.size());
CharBuffer cbuf = Charset.forName("8859_1").newDecoder().decode(bbuf);
return cbuf;
}
public static void main(String[] args){
Pattern pattern = Pattern.compile("oi");
Matcher matcher = pattern.matcher(fromFile("file.txt"));
..
}
}