File Handling - Problem in counting number of records

Hi I have count the total number of records (Lines) in a file

Number of Records = File Size / Record size

Here Record size is fixed

For eg., 4 Records with each record of size 10, then the expected file size is 40. But in my case file size is getting varied in like instaed 40 bytes it says 41 bytes. Because of this I'm facing a problem in counting number of records

Could any one solve this?

Thanks in Advance,

Bala

[461 byte] By [BalaThiruppathya] at [2007-11-27 11:06:12]
# 1

> Hi I have count the total number of records (Lines)

> in a file

>

> Number of Records = File Size / Record size

>

> Here Record size is fixed

>

> For eg., 4 Records with each record of size 10, then

> the expected file size is 40. But in my case file

> size is getting varied in like instaed 40 bytes it

> says 41 bytes. Because of this I'm facing a problem

> in counting number of records

>

> Could any one solve this?

>

> Thanks in Advance,

> Bala

Message was edited by:

snic.snac

snic.snaca at 2007-7-29 13:13:42 > top of Java-index,Java Essentials,Java Programming...
# 2

I think the solution is to debug the code that writes to the file.

Hippolytea at 2007-7-29 13:13:42 > top of Java-index,Java Essentials,Java Programming...
# 3

Coding is pretty simple

File inFile = new File(file);

fileSize = inFile.length();

int recSize = 464;

recCount = fileSize / recSize;

Problem here file size is getting varied

For eg., 4 Records with each record of size 464then

Expected file size = 464 * 4 = 1856

But actual file size which we receive is 1858 (Even in windows file property it shows the same size)

Since size is increased than expected value the record count is calculating wrongly

BalaThiruppathya at 2007-7-29 13:13:42 > top of Java-index,Java Essentials,Java Programming...
# 4

I think the solution is to debug the code that writes to the file.

Hippolytea at 2007-7-29 13:13:42 > top of Java-index,Java Essentials,Java Programming...