Check if a file is a valid SQLite database

前端 未结 1 538
时光说笑
时光说笑 2021-01-28 03:58

I need to check whether a file (with unknown extension) is a valid SQLite database.

My function works fine, but when it fails, the file is still locked after exiting the

相关标签:
1条回答
  • 2021-01-28 04:24

    To determine if a file is an SQLite database, just check the first 16 bytes of the database header.

    from tmighty's comment:

    Public Function IsSqliteDB(ByVal uPath As String) As Boolean
        Dim bytes(16) As Byte
        Using fs As New IO.FileStream(uPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)
            fs.Read(bytes, 0, 16)
        End Using
        Dim text As String = System.Text.ASCIIEncoding.ASCII.GetString(bytes)
        Return text.Contains("SQLite format")
    End Function
    
    0 讨论(0)
提交回复
热议问题