sequential file, line indexing, seeking and readline 
Author Message
 sequential file, line indexing, seeking and readline

I'm experiencing a problem with the System.IO streams and readers.

I have a large sequential file that I am trying to index the char position
of each line so that later on I can just seek to that position and then
issue a streamreader.readline(). What is happening is that occasionally
readline will take a variable fraction of the action string and duplicate
it.

e.g. next line to be read is "abcdef". readline might return "abcabcdef"
The following code is what I am using.

TIA Jason
        Dim x As File
        Dim xbr As BinaryReader
        Dim lcnt As Long

        Dim xo As File
        Dim xsw As StreamWriter

        Dim xi As File
        Dim xsr As StreamReader

        xsw = New StreamWriter(xo.OpenWrite("c:\\result1.dat.cmp"),
System.Text.Encoding.ASCII)
        xbr = New BinaryReader(x.OpenRead("c:\\result1.dat.idx"))
        xsr = New StreamReader(xi.OpenRead("c:\\result1.dat"),
System.Text.Encoding.ASCII)
        lcnt = 0
        Dim bin As Int64
        Dim strout As String
        Try
            While True
                bin = xbr.ReadInt64()
                xsr.BaseStream.Seek(bin, SeekOrigin.Begin)
                strout = xsr.ReadLine
                xsw.WriteLine(strout)
                strout = ""
                lcnt = lcnt + 1
            End While
        Catch oome As EndOfStreamException
            MsgBox("end of stream, all done")
        End Try
        xbr.Close()
        xsr.Close()
        xsw.Flush()
        xsw.Close()
        MsgBox(lcnt)



Mon, 09 May 2005 03:35:52 GMT  
 sequential file, line indexing, seeking and readline
Hi Jason,

I cannot reproduce the problem.

would you please upload a work sample along with your data files?

--
Parker Zhang
Microsoft Developer Support

This posting is provided "AS IS" with no warranties, and confers no rights.



Mon, 09 May 2005 15:55:47 GMT  
 sequential file, line indexing, seeking and readline
Hi,

I think the problem is with the index file.

Where is your binary index file?

How do you create it?

Would you please upload it?

I need result.dat, result.dat.idx.

--
Parker Zhang
Microsoft Developer Support

This posting is provided "AS IS" with no warranties, and confers no rights.



Tue, 10 May 2005 20:27:51 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Accessing a sequential file- line by line

2. Sequential files, Deleting Lines

3. How to Get Past a Line Feed character in Reading a Sequential ASCII File

4. How to Get Past a Line-Feed Character in Reading a Sequential ASCII File

5. Using SEEK on DBF files and indexes

6. Readline only read first character in line

7. trees, sequences, serial, indexed sequential!!!!

8. Text to index sequential

9. generating a unique (sequential) number to subject line

10. Using the FileOpen dialog to find a file to open so I can use ReadLine method

11. Loading text file using StreamReader.Readline()

12. Open a text file and edit using ReadLine method

 

 
Powered by phpBB® Forum Software