here is my code. I store date in dates ArrayList which looks like: [020406,020407...] and I am searching for pattern in files which is something like that:
c001z020102
c002z020103
...
Code:
private void printReaderContent(BufferedReader reader) throws IOException {
String line = null;
for(String tmp : dates) {
while ((line = reader.readLine()) != null) {
if (line.matches("[c]{1}[0-9]{3}[z]{1}" + tmp)) {
xmlCodes.add(line);
} else {
}
}
}
System.out.println(xmlCodes);
}
So I have matches method like in my code and I'm trying to add tmp variable to combine this pattern so I can get selected results from my file. If I use standard pattern like [c]{1}[0-9]{3}[z]{1}[0-9]{2}[0-9]{2}[0-9]{2} it's working, but everytime I put tmp instead i get blank arrayList returned :( I'm using jodaTime to calculate amount of days between and I store it in dates ArrayList:
public void countDatesBetween()
{
int days = Days.daysBetween(dataPierwsza, dataOstatnia).getDays();
for (int i = 0; i <= days; i++)
{
DateTime d = dataPierwsza.withFieldAdded(DurationFieldType.days(), i);
dates.add(d.toString("yyMMdd"));
}
}
I have a file with multiple lines of particular pattern, for example: c001z040206. User puts 2 dates like 2014-06-06 and 2014-06-08 ---> coundDatesBetween creates an arrayList (dates.toString("yyMMdd") which looks like that: [140606, 140607, 140608]. Then I want to search through file with this pattern for c001z which is "[c]{1}[0-9]{3}[z]{1}" and get selected date from tmp which is basically iterating dates ArrayList. So it's should be like that for example: c001z140606 ---> find it in file and return to xmlCodes String ArrayList, but it's just returning blank arraylist.
Aucun commentaire:
Enregistrer un commentaire