Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Reading data from a text - file into 2 or more text files  RSS feed

 
Gabriel Fox
Ranch Hand
Posts: 170
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 111
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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();
 
Gabriel Fox
Ranch Hand
Posts: 170
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Laudney, the code U posted was very
useful.Cheers.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!