So, I'm dealing with integrating a legacy system. It produces a large text file, that prints instructions in one large string. Really large string. We're talking 450 000 characters or more.
I need to break this up in to lines, one per instruction. Each instruction is separated by a five digit code, where the code contains the number of characters in the next instruction.
My solution is writing a small java program that uses a buffered reader to read the file into a string, which is subsequently split into lines, and saved to a new file.
Any advice on handling this? Will a buffered reader be able to read this into a regular string? Am i doing this wrong?
Yes. Use a buffered reader.
Work out the max size of an instruction and create a char[] of that size. Then do something like:
reader.read(charArray, 0, 5);
// parse the header
reader.read(charArray, 0, lengthOfInstruction);
String instruction = new String(charArray, 0, lengthOfInstruction);
// do stuff with the instruction
You put this in a while loop that terminates when the file ends.
This might not be the most run-time efficient, but it's probably good enough and will be simple enough to get working.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With