For getting the regular expressions on the content of a file you must need to use the code provided below:
Code:
import java.io.FileInputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.CharBuffer;
import java.nio.channels.FileChannel;
import java.nio.charset.Charset;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Main
{
public static CharSequence fromFile(String filename) throws IOException
{
FileInputStream fileinputstream = new FileInputStream(filename);
FileChannel filechannel = fileinputstream.getChannel();
ByteBuffer bytebuffer = filechannel.map(FileChannel.MapMode.READ_ONLY, 0, (int) filechannel.size());
CharBuffer charbuffer = Charset.forName("8859_1").newDecoder().decode(bytebuffer);
return charbuffer;
}
public static void main(String[] argv) throws Exception
{
Pattern patt = Pattern.compile("patt");
Matcher match = patt.match(fromFile("infile.txt"));
while (match.find())
{
String string = match.group();
}
}
}
Bookmarks