0
我試圖在vb.net中創建一個程序,它的功能是當您打開一個文件時,將文件打開成十六進制代碼,但問題是,如果我打開一個很大的文件,它通常會導致OutOfMemory異常。打開大文件並將其轉換爲十六進制導致OutOfMemory異常VB.NET
我試過一些東西,但沒有任何工作。
ToolStripLabel1.Text = "Status: Loading"
Cursor = Cursors.WaitCursor
If OpenFileDialog1.ShowDialog <> DialogResult.Cancel Then
Dim infoReader As IO.FileInfo
infoReader = My.Computer.FileSystem.GetFileInfo(OpenFileDialog1.FileName)
If Math.Truncate(infoReader.Length/1024/1024) > 15 Then
Dim x As MsgBoxResult
x = MsgBox("Opening files bigger than 15MB can cause the program to be unresponsive for long periods of time, crash or throw a OutOfMemory exception, depending on the size of the file." & vbCrLf & vbCrLf & "Are you sure you want to continue loading this file?", MsgBoxStyle.Exclamation + MsgBoxStyle.YesNo, "Warning - HEX EDITOR")
If x = MsgBoxResult.Yes Then
RichTextBox1.AppendText(String.Join(" ", File.ReadAllBytes(OpenFileDialog1.FileName).Select(Function(b) b.ToString("X2")))) 'This is where the exception would happen.
ToolStripLabel1.Text = "Status: Idle"
End If
Else
RichTextBox1.Text = String.Join(" ", IO.File.ReadAllBytes(OpenFileDialog1.FileName).Select(Function(b) b.ToString("X2")))
ToolStripLabel1.Text = "Status: Idle"
End If
End If
RichTextBox2.Text = RichTextBox1.Text
NumericUpDown3.Maximum = RichTextBox1.Text.Length
NumericUpDown2.Maximum = RichTextBox1.Text.Length
NumericUpDown3.Value = RichTextBox1.Text.Length
Cursor = Cursors.Default
Label4.Text = "File Opened: " & OpenFileDialog1.FileName
感謝稱呼它,我在想這樣做,但我不知道如何做到這一點沒有崩潰,或使錯誤。 – Coolvideos73
我有一個問題,我無法保存,Invaild投射異常如果SaveFileDialog1.ShowDialog <> DialogResult.Cancel Then Dim b As Byte()= RichTextBox1.Text.Split(「」c).Select(Function( n)Convert.ToByte(Convert.ToInt32(n,16))) My.Computer.FileSystem.WriteAllBytes(SaveFileDialog1.FileName,b,False) End If – Coolvideos73
與原始問題有什麼共同點?請發佈一個新問題。 – Steve