This might help you in reading in file http://www.homeandlearn.co.uk/java/read_a_textfile_in_java.html
Do a loop that read each line of the text
Since you already know the order of the data (student number, subject and mark), you can use mod 2 to record the subject and mod 3 to record the mark. If it's < 50 ( assuming 50 is passing) put it in the fail.txt. If its >=50 write it in pass.txt. You can use a data structure temporarily such as linked list or 2d arrays to store the results for pass and fail. Read those 2 linked list or array whichever you prefer and write it in the text file. Hope it helps.