Reading data from a text - file into 2 or more text files
Gabriel Fox
Ranch Hand
Joined: Oct 17, 2001
Posts: 170
posted
0
Hi, I am not sure if this is the right Forum for this problem but i need help please... Question: How do i read one text file (with high capacity of data)from my local drive to MORE THAN one text file ,with ability to specify what portion of the source text file is needed for tranfer to different destination textfiles. Codes will be appreciated please.Cheers.
Laudney Ren
Ranch Hand
Joined: Jan 06, 2002
Posts: 111
posted
0
Suppose the source files is named "source.txt", then try the following: FileInputStream fin = new FileInputStream("source.txt"); byte[] bytearray; byte flag; int index = 0; int name = 1; While(true) { flag = fin.read(); bytearray[index++] = flag; if (flag == "some flag to seperate the source") FileOutputStream fout = new FileOutputStream("text" + name + ".txt"); fout.write(bytearray); fout.close(); name++; index = 0; } fin.close();
" Veni, vidi, vici "<br />" I came, I saw, I conquered "
Gabriel Fox
Ranch Hand
Joined: Oct 17, 2001
Posts: 170
posted
0
Thanks Laudney, the code U posted was very useful.Cheers.
subject: Reading data from a text - file into 2 or more text files