Hi guys,
i m having problem with reading the large file and splitting the file inot multiple files..
the sample large file as follows:
================================
the number is
the file number name is a1.txt
823
3232
232
233
3232
end number
the number is
the file number name is a2.txt
823
3232
232
233
3232
end number
the number is
the file number name is a3.txt
823
3232
232
233
3232
end number
the number is
the file number name is a4.txt
823
3232
232
233
3232
end number
the number is
the file number name is a5.txt
823
3232
232
233
3232
end number
i want to create separate files reading the file.ex:in the above sample file it should create files if the line starts with the "number is--" and ends with "end number.." like this i want to create file reading the complete large file..
i m able to read the file but i m not able to write into files...
sample code as follos:
import java.io.*;
public class Pintest {
public static void main (
String[] args) throws Exception {
Pintest f = new Pintest();
String pfile=args[0];
f.readMyFile(pfile);
}
void readMyFile(String file) {
try {
BufferedReader in = new BufferedReader(new FileReader(file));
String str;
int count=2;
while ((str = in.readLine()) != null) {
count++;
if(str.startsWith("the number is")){
int cnt=count+2;
BufferedWriter out = new BufferedWriter(new FileWriter("pin"+count+".pin"));
System.out.println(str);
in.readLine();
out.write(str);
}
}
in.close();
} catch (Exception e) {
}
}
}
here i m getting only one line output i.e.."the number is" in the every generate file..
thanks in advance