0

Hello,

so my question is this..lets say you have a file
like this.

Computer Science
01 //course number
30 //number of students that can enroll
4 //number of students currently enrolled

Math
02 //course number
20 //number of students that can enroll
12 //number of students currently enrolled

And i have a program that enrolls students in a course..
after a student enrolls, i need to update the file.

so if i enroll in computer science,
the number of students would increase to 5 and look like this

Computer Science
01
30
5

...how do i do that?

2
Contributors
3
Replies
4
Views
6 Years
Discussion Span
Last Post by NormR1
0

You've shown the file contents in text record format. Ie each record ends with a line end. The records can all be different lengths.
To be able to use a RandomAccessFile to get to records randomly, each record must be the same length. Then the position of a record = (recordNbr-1) * record length

Is your data is written to the file with fixed/same length records?

0

the format is all the same and predictable because i created the file

0

Ok, then if you know the position/displacement of all the fields you should be able to use RandomAccessFile to update the file.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.