Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.BufferedInputStream;
- import java.io.File;
- import java.io.FileInputStream;
- import java.io.FileNotFoundException;
- import java.io.IOException;
- import java.util.regex.Matcher;
- import java.util.regex.Pattern;
- public class FileParser {
- /**
- *
- * @param args
- */
- public static void main(String[] args) {
- Pattern pattern = Pattern.compile(
- "(0[1-9]|1[0-2])/(0[1-9]|[1-2][0-9]|30|31)/([0-9]{4})",
- Pattern.CASE_INSENSITIVE);
- File file = new File("corpusCFPs-set1.txt");
- String fileContent = readFileAsString(file.getAbsolutePath());
- Matcher match = pattern.matcher(fileContent);
- while (match.find()) {
- System.out.println("extrait : " + match.group());
- }
- }
- /**
- *
- * @param filePath
- * @return
- */
- private static String readFileAsString(String filePath) {
- byte[] buffer = new byte[(int) new File(filePath).length()];
- BufferedInputStream f = null;
- try {
- f = new BufferedInputStream(new FileInputStream(filePath));
- } catch (FileNotFoundException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- try {
- f.read(buffer);
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- if (f != null)
- try {
- f.close();
- } catch (IOException ignored) {
- }
- return new String(buffer);
- }
- }
Add Comment
Please, Sign In to add comment