You have to use javas handling mechanism for that. If you are unaware of this, then this link may help
For the file you are opening for reading and writing, first you need to identify what is the length of each column, like dept name, number of semester etc., and then send data limited to that length.
Then read the data coming to you as Input, parse it by assigning data for each column to a variable or form a single String using a delimiter like (|), for all columns, and then write to the file.
Same for reading....