Create a file
Dim as String String. Format ("C:\ErrorLog.txt", DateTime.Today.ToString ("dd-mmm-yyyy " String. Format ("Error Message in occured at--{0}{1}", DateTime.Now, Environment.NewLine))
The first sentence means to create a ErrorLog.txt text document below the C drive, and the second sentence means to write "Error Message in occured at--followed by the current time in this text document, and a line for each sentence."
The above is written directly from the local disk, so if you want to read the suffix. bin file from the database, and then write to the local disk how do you do it?
Reading files from a database
'read the bin file in the database DimBlobfiles as Integer=0 TrySystem.IO.Directory.CreateDirectory ("C:\var\") myCommand.CommandText="Select Blobfile from evnet.join_server_firmware_version ORDER BY dttdatetime Desc" 'read the file field from the database up to date DimDr asMysqldatareader =mycommand.executereader () Dr. Read ()DimB (Dr. GetBytes (Blobfiles,0, Nothing,0,Integer. MaxValue)-1) as Byte 'declare b array to hold the read to DrDr. GetBytes (Blobfiles,0B0, B.length)'The number read from B is stored in the BlobfilesDr. Close () Conn. Close () Conn. Open () myCommand.CommandText="Select Vchfimware_versionname from evnet.join_server_firmware_version ORDER BY dttdatetime Desc"Versionname=Mycommand.executescalar Conn. Close ()IfSystem.IO.File.Exists ("C:\var\"+ Versionname +". txt") Then 'determine if the folder is currently stored on the C drive Else DimFs12 as NewSystem.IO.FileStream ("C:\var\"+ Versionname +". txt", FileMode.OpenOrCreate, FileAccess.ReadWrite, Fileshare.readwrite)'Create a change file without theFs12. Write (b, Blobfiles, b.length)'start writing to the file you created and finish it all at onceFs12. Close ()'turn off read and write operations to avoid throwing exceptionsfs12. Dispose ()End If '====================== CatchEx asException Debug.Print ("#######################"&Ex. StackTrace) Debug.Print ("########"&Ex. Message)ThrowexEnd Try
Read Only 2014-length bytes at a time
DimFs as NewSystem.IO.FileStream ("C:\var\"+ Versionname +". txt", IO. FileMode.Open, IO. FileAccess.Read)DimBuffer1023) as Byte DimRe as NewSystem.IO.BinaryReader (FS)DimNumdouble as Double= (fs. Length/1024x768) Num=math.ceiling (numdouble) ' This function is used to determine if there are decimals, a decimal will be automatically rounded such as: 1.2 will take 2, 1.6 will take 2 fs. Seek (i*BYNUM.C, Seekorigin.begin) re. Read (Buffer,0,1024x768)'represents starting from 0 bits read 1024 bits if you want to take the packet length available in buffer. Length if you want to fetch the data, it is directly preferable to buffer
End
vb.net create files and read and write files