BufferedReader in = new BufferedReader(new FileReader("Results.log"));
while((str=in.readLine())!=null){
if(str.startsWith("APDU")){
list.add(str);
System.out.println(str);
}
}
In the above code snippet i have provided the condition for the first line.
How to specify the condition for the second line
> BufferedReader in = new BufferedReader(new
> FileReader("Results.log"));
>
> while((str=in.readLine())!=null){
> if(str.startsWith("APDU")){
> list.add(str);
> System.out.println(str);
> }
>
> }
> above code snippet i have provided the condition for
> the first line.
> ow to specify the condition for the second line
Please use the [url http://forum.java.sun.com/help.jspa?sec=formatting]Code Formatting
Tags[/url].
This code just reads the first line. You want to keep reading until you get to different line, right?
Inside your while loop you will want to something like this:
if(isThisSecondLine()){
break;
}
if(hasFirstLineOccurred()){
doSomethingWithThisLine();
}
BufferedReader in = new BufferedReader(new FileReader("Results.log"));
while((str=in.readLine())!=null){
if(str.startsWith("APDU")){
if(str.startsWith("Time"))
break;
else
System.out.println(str);
}
}
I have given the above statements to print the information between two non-consecutive lines. But it's not working.
Can any one suggest me a way to do this.
BufferedReader in = new BufferedReader(new FileReader("Results.log"));
boolean logging = false;
while((str=in.readLine())!=null){
if(str.startsWith("APDU")){
logging = true;
list.add(str);
System.out.println(str);
}
else if(logging) {
list.add(str);
System.out.println(str);
if(str.startsWith("END"))
logging=false;
}
}
You'll, of course, need to replace END with whatever you're looking for to end the log. And if you want to end the while loop immediately after it reads the END part, just change that statement to:
if(str.startsWith("END")) {
logging = false;
break;
}
BufferedReader in = new BufferedReader(new FileReader("Results.log"));
boolean logging = false;
while((str=in.readLine())!=null){
if(str.startsWith("APDU")){
logging = true;
list.add(str);
System.out.println(str);
}
else if(logging) {
list.add(str);
System.out.println(str);
if(str.startsWith("END"))
logging=false;
}
}
The above code worked fine with one small change.
after the statement
if(str.startsWith("END"))
we should add break;
instead of logging=false;
Thanks