S
scopp
Hi there,
Please bare with me on this, I'm a newbie ). Ok, I'm trying to read a
file (a bunch of 1 word lines), find the last line with the word "SKIP" at
the end, and get the next line. After getting the desired line, I want to
append the word "SKIP" to that line as well and save and close the file.
I also want the class to have an input parameter (integer), which will be
the same name of the file (example: input = 1234 --> filname = 1234.txt).
Here is what I've got so far:
import java.io.*;
public class GetLine {
int number; //let's say the lines in the file are all 5 digit
numbers, with no spaces
public boolean evaluate(String str) {
//
//I'm not sure how to evaluate if the end of the line
has the word SKIP and the following doesn't work????
//
if ( StringBuffer.indexOf("SKIP\n") )
return true;
}
public void get(int c) throws IOException, FileNotFoundException {
String line;
boolean b;
FileReader fr=new FileReader(number + ".txt");
BufferedReader br=new BufferedReader(fr);
while((line=br.readLine())!=null )
{
b = evaluate(line);
if (b==false)
{
//
//not sure if I can just do a "return
line" to get the first line found without SKIP???
return line;
//
//not sure if I can do the following
either???
//
line = line + "SKIP";
}
}
}
}
Please, any suggestions are apprciated. Thanks for your help.
scopp
Please bare with me on this, I'm a newbie ). Ok, I'm trying to read a
file (a bunch of 1 word lines), find the last line with the word "SKIP" at
the end, and get the next line. After getting the desired line, I want to
append the word "SKIP" to that line as well and save and close the file.
I also want the class to have an input parameter (integer), which will be
the same name of the file (example: input = 1234 --> filname = 1234.txt).
Here is what I've got so far:
import java.io.*;
public class GetLine {
int number; //let's say the lines in the file are all 5 digit
numbers, with no spaces
public boolean evaluate(String str) {
//
//I'm not sure how to evaluate if the end of the line
has the word SKIP and the following doesn't work????
//
if ( StringBuffer.indexOf("SKIP\n") )
return true;
}
public void get(int c) throws IOException, FileNotFoundException {
String line;
boolean b;
FileReader fr=new FileReader(number + ".txt");
BufferedReader br=new BufferedReader(fr);
while((line=br.readLine())!=null )
{
b = evaluate(line);
if (b==false)
{
//
//not sure if I can just do a "return
line" to get the first line found without SKIP???
return line;
//
//not sure if I can do the following
either???
//
line = line + "SKIP";
}
}
}
}
Please, any suggestions are apprciated. Thanks for your help.
scopp