I would suggest using a memory-mapped file. You could then do all your manipulation in memory then have Windows dump the memory back out to the file.
.NET 1.1 doesn't have inherent support for memory-mapped files; but there's at least one class that wraps the required PInvoke code: http://www.winterdom.com/dev/dotnet/FileMap-2.0.2.zip at http://www.winterdom.com/dev/dotnet/. That class only gives access to the memory via a Stream object; but it's a good place to start. http://www.peterritchie.com/ On Fri, 18 Nov 2005 12:22:18 +0000, Girish Jain <[EMAIL PROTECTED]> wrote: >Hi All, > >I am writing a log file with the requirement that the latest entry in the >log should be on the top. For the purpose I looked for ways of doing that >but ended up by reading the entire contents of the existing file into a byte >array and then re-write the file with the new content. Is there any better >way possible? > >The current code > >// Firstly read the existing file and take the contents >// into a byte array >//------------------------------------------------------------ >fs = new FileStream(m_strFilePath, FileMode.Open, FileAccess.Read); >byte[] arrOriginalText = new byte[fs.Length]; >fs.Read(arrOriginalText, 0, arrOriginalText.Length); >fs.Close(); fs = null; >//------------------------------------------------------------ > > >// Now write the data to the file by re-creating the new file >//------------------------------------------------------------ >fs = new FileStream(m_strFilePath, FileMode.Create, FileAccess.Write); > > >// Convert the new data to be written to a byte array >//------------------------------------------------------------ >byte[] arrNewText = new byte[ strData.Length ]; >Encoding.UTF8.GetBytes( strData, 0, strData.Length, arrNewText, 0 ); > > >// Now write data - first the new text and then the original >//------------------------------------------------------------ >fs.Write(arrNewText, 0, arrNewText.Length); >fs.Write(arrOriginalText, 0, arrOriginalText.Length); =================================== This list is hosted by DevelopMentorĀ® http://www.develop.com View archives and manage your subscription(s) at http://discuss.develop.com
