Imports System.IO Public Class SaveClass Public Function GetContents(ByVal FullPath As String) Dim contents As String Dim read As StreamReader Try read = New StreamReader(FullPath) contents = read.ReadToEnd read.Close() Return contents Catch ex As Exception MsgBox(ex.Message) End Try End Function Public Function SaveTextToFile(ByVal strData As String, _ ByVal FullPath As String) As Boolean Dim objReader As StreamWriter Try objReader = New StreamWriter(FullPath, True) objReader.WriteLine(strData) objReader.Close() Return True Catch Ex As Exception Return False End Try End Function
public bool EsCabeceraPDF(string fileName) { byte[] buffer = null; FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read); BinaryReader br = new BinaryReader(fs); long numBytes = new FileInfo(fileName).Length; //buffer = br.ReadBytes((int)numBytes); buffer = br.ReadBytes(5); var enc = new ASCIIEncoding(); var header = enc.GetString(buffer); //%PDF−1.0 // If you are loading it into a long, this is (0x04034b50). if (buffer[0] == 0x25 && buffer[1] == 0x50 && buffer[2] == 0x44 && buffer[3] == 0x46) { return header.StartsWith("%PDF-"); } return false; }
Private Sub cmdCreateLog_Click() Dim lngLocation As Long Dim strLine As String Open "c:\test.pdf" For Binary As #1 ' Open file just created. Open "c:\pdfTest.txt" For Output As #2 Do While lngLocation < LOF(1) ' Loop until end of file. strLine = Input(1, #1) ' Read character into variable. lngLocation = Loc(1) ' Get current position within file. Print #2, lngLocation & " " & Replace(Replace(strLine, vbLf, "line feed"), vbCr, "carriage return") & vbCrLf; Loop Close #1 ' Close file. Close #2 End End Sub
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre question