file should be only 1kb

bcm

Well-known member
Joined
Aug 13, 2007
Messages
56
Programming Experience
Beginner
I want to create a text file whose size should be only 1kb. The datashould not exceed more than that.
How can I do that in VB.NET?
:confused:
 
Give your threads relevant titles. Thread was given a relevant title.
VB.NET:
Dim bytes(999) As Byte
Dim fs As New IO.FileStream("1kbfile", FileMode.Create, FileAccess.Write)
fs.Write(bytes, 0, bytes.Length)
fs.Close()
 
VB.NET:
Dim bytes(999) As Byte
[/QUOTE]

Dim bytes(1024) As Byte, surely!? ;)

But maybe easier something like (not syntax checked):

File.WriteAllText(Iif(myString.Length > 1024, myString.Substring(0,1024), myString), Encoding.ASCII)
 
Dim bytes(1024) As Byte, surely!? ;)

But maybe easier something like (not syntax checked):

File.WriteAllText(Iif(myString.Length > 1024, myString.Substring(0,1024), myString), Encoding.ASCII)
I usually read small "k" as SI unit kilo (1000), large "K" as non-standardized legacy/computer kilo (1024). Also bytes(1024) would be 1025 bytes...

.Net 1 doesn't have a WriteAllText method.
 
I usually read small "k" as SI unit kilo (1000), large "K" as non-standardized legacy/computer kilo (1024).
Bwahahaah.. John, dang.. You kill me, you really do. Youre a proper funny guy, and I love your posts. Hopefully you'll find it a compliment to know I think of you like I do Data in Star Trek - hilarious and amazing because he's absolutely right on every occasion and works with infallible precision.

Also bytes(1024) would be 1025 bytes...
Indeed, that's one of those VB idiosyncracies (stupidities IMHO) that a C# programmer will forget quite easily..

.Net 1 doesn't have a WriteAllText method.
And I'm normally pretty good with that too. Good to know that when I'm wrong on the 1% of occasions, there's John as the backup.. :p You want a job? :)
 
Indeed, that's one of those VB idiosyncracies (stupidities IMHO) that a C# programmer will forget quite easily..
It's the little differences... anyway OP should get the idea from both suggestions.
You want a job? :)
I'm fully booked for the time being, but thanks for offer ;)
 
Yeah. Wouldn't an uppercase K be Kelvin? :p "KB" is the proper notation for kilobyte and a kilobyte is always 1024 bytes (never 1000). :)
 
Ah.. therein lies the final nitpick; kb most definitely and resolutely means kilobits, regardless of what size we are attributing to the kilo part, we really should be advising the OP to make an array of Byte(124) or Byte(127) ;)
 
Back
Top