Does anyone know how to change the value of FS.Length? I keep getting that it's read only.

I need to read a file, let's say it's 100 bytes in size. After some data manipulation, the file becomes 40 bytes. When I write the file back , it writes the 40 bytes plus the remainder of the file thus the file remains at 100 bytes.

I know that if I read the file as File A, write it back as File B and then delete File A would probably work but I want to overwrite the existing file.

I have noticed the the value of FS.Length does not change although the data string that I am writing is 40 bytes.

Here's what I have so far:

fs = f.open
lBytes = fs.Length

Dim fileData(lBytes) As Byte
fs.Read(fileData, 0, lBytes)
ModifyFileData(fileData)
fs.Close()

fs = f.OpenWrite
fs.Write(fileData, 0, fileData.Length)
fs.Close()

The code may not be pretty but it's a start.

I was able to resolve the problem.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.