473,500 Members | 1,967 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Write Data To File

Hi EveryBody:

How can I write a byte array to FileStream, I tried to do so and I use the
following code:
Dim rawan As New List(Of Byte())
Dim msg() As Byte = CType(rawan(TextBox1.Text), Byte())
Dim File_Name As String = "Winter.jpg"
Dim fs As New FileStream(File_Name, FileMode.CreateNew)
' Create the writer for data.
Dim w As New BinaryWriter(fs)
' Write data to Test.data.
Dim i As Integer
For i = 0 To msg.Length
w.Write(CInt(i))
Next i
w.Close()
fs.Close()

But I got the following message Can not can't not access file. So how can I
write my data to file or file stream? any help will be appreciated

regard's

Husam
Jan 20 '08 #1
9 2180
Husam wrote:
How can I write a byte array to FileStream, I tried to do so and I
use the following code:
[...]

If you're using VS2005 or later (you didn't say if you were) and you want to
write a byte array to a file, this is an easier solution:

\\\
IO.File.WriteAllBytes("Winter.jpg", msg)
///

HTH,

--

(O)enone
Jan 20 '08 #2
(O)enone is right, but in your code you don't have any Open calls on your
stream or writer. That would be necessary.

"Husam" wrote:
Hi EveryBody:

How can I write a byte array to FileStream, I tried to do so and I use the
following code:
Dim rawan As New List(Of Byte())
Dim msg() As Byte = CType(rawan(TextBox1.Text), Byte())
Dim File_Name As String = "Winter.jpg"
Dim fs As New FileStream(File_Name, FileMode.CreateNew)
' Create the writer for data.
Dim w As New BinaryWriter(fs)
' Write data to Test.data.
Dim i As Integer
For i = 0 To msg.Length
w.Write(CInt(i))
Next i
w.Close()
fs.Close()

But I got the following message Can not can't not access file. So how can I
write my data to file or file stream? any help will be appreciated

regard's

Husam
Jan 20 '08 #3
Husam,

Can you have a look what happens when you set option Strict to on, I have
the idea that you want to write nothing.

Cor

Jan 20 '08 #4
"(O)enone" <oe****@nowhere.comschrieb:
>How can I write a byte array to FileStream, I tried to do so and I
use the following code:
[...]

If you're using VS2005 or later (you didn't say if you were) and you want
to write a byte array to a file, this is an easier solution:

\\\
IO.File.WriteAllBytes("Winter.jpg", msg)
///
.... or 'My.Computer.FileSystem.WriteAllBytes', which does pretty much the
same as the above.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Jan 20 '08 #5
"Herfried K. Wagner [MVP]" <hi***************@gmx.atwrote in message
news:ue**************@TK2MSFTNGP06.phx.gbl...
"(O)enone" <oe****@nowhere.comschrieb:
>>How can I write a byte array to FileStream, I tried to do so and I
use the following code:
[...]

If you're using VS2005 or later (you didn't say if you were) and you want
to write a byte array to a file, this is an easier solution:

\\\
IO.File.WriteAllBytes("Winter.jpg", msg)
///

... or 'My.Computer.FileSystem.WriteAllBytes', which does pretty much the
same as the above.
What a pair of morons you two are. He's using a BinaryWriter, in case you
hadn't noticed.


Jan 21 '08 #6
"Guru" <ru*****@interference.nitschrieb:
>>>How can I write a byte array to FileStream, I tried to do so and I
use the following code:
[...]

If you're using VS2005 or later (you didn't say if you were) and you
want to write a byte array to a file, this is an easier solution:

\\\
IO.File.WriteAllBytes("Winter.jpg", msg)
///

... or 'My.Computer.FileSystem.WriteAllBytes', which does pretty much the
same as the above.

What a pair of morons you two are. He's using a BinaryWriter, in case you
hadn't noticed.
There is no reason to use 'BinaryWriter' in this particular case.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Jan 21 '08 #7
"Herfried K. Wagner [MVP]" <hi***************@gmx.atwrote in message
news:uJ****************@TK2MSFTNGP02.phx.gbl...
"Guru" <ru*****@interference.nitschrieb:
>>>>How can I write a byte array to FileStream, I tried to do so and I
use the following code:
[...]

If you're using VS2005 or later (you didn't say if you were) and you
want to write a byte array to a file, this is an easier solution:

\\\
IO.File.WriteAllBytes("Winter.jpg", msg)
///

... or 'My.Computer.FileSystem.WriteAllBytes', which does pretty much
the same as the above.

What a pair of morons you two are. He's using a BinaryWriter, in case you
hadn't noticed.

There is no reason to use 'BinaryWriter' in this particular case.
That is not your decision to make, it is the OP's.
Jan 21 '08 #8
"Guru" <ru*****@interference.nitschrieb:
>>>>If you're using VS2005 or later (you didn't say if you were) and you
want to write a byte array to a file, this is an easier solution:
>
\\\
IO.File.WriteAllBytes("Winter.jpg", msg)
///

... or 'My.Computer.FileSystem.WriteAllBytes', which does pretty much
the same as the above.

What a pair of morons you two are. He's using a BinaryWriter, in case
you hadn't noticed.

There is no reason to use 'BinaryWriter' in this particular case.

That is not your decision to make, it is the OP's.
It's simply a bad idea to use 'BinaryWriter' if you want to persist an array
of bytes forming a file's contents.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Jan 21 '08 #9
Herfried,

What did you often write, I have showed it you by email lately, although I
could not resist a minute ago a reply to the troll, let us think about that.

Cor

Jan 22 '08 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
7371
by: Ellixis | last post by:
Hello, How can I use fwrite() and fseek() in order to write data in the middle (or anywhere else) of a file without overwriting existing data ? People told me that I should load the file into...
7
2709
by: Bob | last post by:
Hi, I am trying to use BULK INSERT with format file. All of our data has few bytes of header in the data file which I would like to skip before doing BULK INSERT. Is it possible to write...
9
8263
by: ALI-R | last post by:
Hi,, I have two questions : 1) Is it mandatory that config file of a desktop application must be App.config 2) Is it possible to update config file in your code?? thanks for your help. ALI
2
12581
by: agphoto | last post by:
There is big or problem in open file in read and write mode.. $file = "data.txt"; $fp = fopen($file,"w+"); $line = fgets($fp,"120"); // i need only 1st line to read and upto 120 bytes echo...
4
4659
by: Billy | last post by:
Hi all, I'm building a text file from a database table using the ASP Write Method and would like to position the cursor in a specific column position before writing the fields. As I loop through...
9
6909
by: andy.z | last post by:
If 2 people try to access the same text file at the same time to write to it - what happens in PHP ? What I mean is - presumably the first will be ok - But what will the second person actually...
6
18286
by: globalrev | last post by:
i ahve a program that takes certain textsnippets out of one file and inserts them into another. problem is it jsut overwrites the first riow every time. i want to insert every new piece of...
1
2027
by: xiao | last post by:
HI~ guys , I have a program here (Sorry it is very long about 240 lines.) It can read and write the header information successfully but it cannot write the array successfully. I guess there is...
1
3917
by: Sachin Garg | last post by:
I have a program which opens a fstream in binary input+output mode, creating the file if it doesn't exists. But writing doesn't works after reading, it must be something obvious that I am not aware...
8
28311
blazedaces
by: blazedaces | last post by:
So I have a program below which writes an excel file with multiple sheets based on inputs of sheet names, data, cell types, etc. It uses Apache POI, which is currently the only thing I found...
0
7018
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7232
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7397
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5490
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4923
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3110
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3106
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1430
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
316
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.