Bonsoir,
Je veux détecter la structure Date dans un texte.
j'ai essayé avec ce 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.*;
public class TimeDetection {
// Converts the contents of a file into a CharSequence
// suitable for use by the regex package.
public static 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) {
try {
// Create matcher on file
Pattern pattern = Pattern.compile("dd/MM/yyyy hh:mm:ss");
Matcher matcher = pattern.matcher(fromFile("nb.txt"));
// Find all matches
while (matcher.find()) {
// Get the matching string
String match = matcher.group();
}
} catch (IOException e) {
}
}
}
avec le contenu du fichier
Event: Miami Heat vs. Orlando Magic
Venue: American Airlines Arena
Start: 11/3/2011 8:00:00 PM
Category: SPORTS BASKETBALL
mais aucun résultat pour le pattern recherché.
Pouvez-vous m'aider à résoudre le problème?