Hi How Can ı write
"
FF"
hex
value
in
my file until my write
byte
?
for
example
"
if ı write textbox "
10
"
and press button after program write 10 mb ff hex value in my file"
like
this
https:
ı use
this
code but write
10
mb files only
1
bytes ff
value
like
this
https:
What I have tried:
<pre lang=
"
vb"
>
Dim hex As
String
=
"
FF"
Using fs As New FileStream(
"
huge_dummy_file"
, FileMode.Create, FileAccess.Write)
For Each byteHex As
String
In hex.Split()
fs.Seek(TextBox1.Text *
1024
*
1024
, SeekOrigin.Begin)
fs.WriteByte(Convert.ToByte(byteHex,
16
))
End Using
If you're expecting a 10MB file to be written with that code, it's not. You're seeking out to 10MB of length and then writing a couple of bytes. You're not even writing the bytes 0xFF. You're writing the characters "FF", which is not the same thing.
To write the bytes for 0xFF, you have to write actual bytes, not strings. You also have to write them by the millions, not seek out to a position and do a single write operation.
Dim
hex
As
Byte
= &HFF
Using
fs
As
New
FileStream(
"
file.dat"
, FileMode.Create, FileAccess.Write)
For
x
As
Integer
=
1
To
(
10
*
1024
*
1024
)
fs.WriteByte(hex)
End
Using
Read the question carefully.
Understand that English isn't everyone's first language so be lenient of bad
spelling and grammar.
If a question is poorly phrased then either ask for clarification, ignore it, or
edit the question
and fix the problem. Insults are not welcome.
Don't tell someone to read the manual. Chances are they have and don't get it.
Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
No single item in .NET can be larger than 2GB, so you can't create a byte array that big.
If you must create files that size (and even for testing, 50GB of the same value is rather silly) then create a 1GB array, and append it to the output file 50 times, or a 1MB array, and append it 50,000 times.
But the best is not to create it in the first place!