The moose likes I/O and Streams and the fly likes Reading data from a text - file into 2 or more text files Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » I/O and Streams
Reply Bookmark "Reading data from a text - file into 2 or more text files" Watch "Reading data from a text - file into 2 or more text files" New topic
Author

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

Gabriel Fox
Ranch Hand

Joined: Oct 17, 2001
Posts: 170
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
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
Thanks Laudney, the code U posted was very
useful.Cheers.
 
 
subject: Reading data from a text - file into 2 or more text files
 
Threads others viewed
Import from and export to Excel
parsing
text files creation
Reading and writing text files in oracle database......
file handling through javascript
WebSphere development made easy
without the weight of IBM tools
http://www.myeclipseide.com

cast iron skillet 49er

more from paul wheaton's glorious empire of web junk: cast iron skillet diatomaceous earth rocket mass heater sepp holzer raised garden beds raising chickens lawn care CFL flea control missoula heat permaculture