I want to make a program that reads a file line by line and then writes those lines to another file. I want to solve this problem using two separate Threads. The first Thread reads a line and then passes it to the other Thread, which is responsible for writing that line to another file, via message. This process should be repeated until end of file is reached.
How can I do this?
What you want is a producer-consumer model. That’s not very hard to implement using two
Threadobjects and an ArrayBlockingQueue. Here’s some start-up code:Hope this helps. I cannot give the full code, it’s better if you try to fill the gaps yourself.