Hello,
here is a code for retrieving some lines from a text file.
i'd like to extract data from line2 to line4 ---> this is working
but in the same time i want to data from Line10 to line12
here is the code, my conditions is not working:
Thank you
import java.io.*;
public class ReadSpecificLine
{
public static void main(String[] args)
{
StringBuffer buffer = new StringBuffer();
String line = "";
int lineNo=0;
try
{
LineNumberReader ln = new LineNumberReader(new FileReader("C://Source/Source.txt"));
int count = 0;
while (ln.readLine() != null) {
count++;
}
ln.close();
FileReader fr = new FileReader("C://Source/Source.txt");
BufferedReader br = new BufferedReader(fr);
for (lineNo = 1; lineNo <= count; lineNo++){
if (lineNo == 2)
{
for (lineNo = 2; lineNo <= 4; lineNo++) && (lineNo = 10; lineNo<=14; lineNo++)
{
buffer.append(br.readLine());
//buffer.append("\n");
}
} else
br.readLine();
}
BufferedWriter bw=new BufferedWriter(new FileWriter(new File("C://Target/Target.txt"),true));
bw.write(buffer.toString());
bw.newLine();
bw.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}