一致したデータをXMLとして直接保存できるように、Javaで正規表現を作成するにはどうすればよいですか?
2 に答える
0
のようなものを使用します
public CharSequence fromFile(String filename) throws IOException {
FileInputStream input = new FileInputStream(filename);
FileChannel channel = input.getChannel();
// Create a read-only CharBuffer on the file
ByteBuffer bbuf = channel.map(FileChannel.MapMode.READ_ONLY, 0, (int)channel.size());
CharBuffer cbuf = Charset.forName("8859_1").newDecoder().decode(bbuf);
return cbuf;
}
次のように比較します。
try {
// Create matcher on file
Pattern pattern = Pattern.compile("pattern");
Matcher matcher = pattern.matcher(fromFile("yourFile.txt"));
// Find all matches
while (matcher.find()) {
// Get the matching string
String match = matcher.group();
}
} catch (IOException e) {
}
于 2012-05-02T08:14:33.410 に答える