Hello everyone,
I try to read a stream and save it as byte array to add it later to zip file.
this is the code that I use -
Dim totalbytes As Byte() = Nothing
-
Dim iBytesRead As Integer
-
Dim sChunks As FileStream = File.OpenRead("c:\myfile.wav")
-
Dim Totalread As Int64 = 0
-
ReDim totalbytes(sChunks.Length)
-
Do
-
iBytesRead = sChunks.Read(totalbytes, Totalread, Totalread+ 1048576)
-
Totalread+= iBytesRead
-
Loop While Not iBytesRead = 0
-
sChunks.Close()
-
Return totalbytes
-
but there is something is not correct,
Can you please help me in that.
Thank you
3 7459
Here's how I do my reading in C# : - FileStream fs = File.OpenRead(filePath);
-
byte[] buffer = new byte[fs.Length];
-
fs.Read(buffer, 0, (int)fs.Length);
-
fs.Flush();
-
fs.Close();
So I would suggest cutting out your lines 6 through 9 and replacing them with something like this: - sChunks.Read(totalbytes, 0, totalbytes.Length)
You might have to cast totalbytes.Leng th from an Int 64 to an Int 32, but I forget how to cast in VB.NET.
Hope that helps.
[EDIT]
For future reference, "there is something is not correct" is not a good enough explanation. You need to tell us what it is doing wrong, and what, if any, exceptions you are getting. Please be more descriptive in the future.
Thank you for reply
Actually I can read all bytes by File.ReadAllByt es but I need to read this file with progress.
If I read it byte by byte it will take a long time (it is take more than 5 min to read 30MB).
So I think about this way, but there is something wrong, I dont know what is it.
Finally, I am sorry about my English.
Thanks
Also I found this sample on internet, but because I dont know c# then I dont understand it.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Brian |
last post by:
I'm having intermittent trouble with a call to the Read method of
the HttpWebResponse object. I get an ArumentOutOfRangeException
claiming that deep down inside of the Read method, the count parameter
of the BlockCopy method is showing up as a negative number. Don't
know where the negative number is coming from since I've passed the
value of 1024 to the Read and Write methods. I've even tested the
value of buffer.Length and size at the...
|
by: CroDude |
last post by:
Hi all!
I have problems when writting bitmap to a byte array and after reading it
back form byte to Bitmap object.
What I do is this: First I throw Bitmap to a memory-stream and then I write
it into byte from a stream.
Exception (System.ArgumentException: Invalid parameter used) occurs when
reading from byte over a memory-stream back to the Bitmap object.
Please help, I'm really stuck here!
Here's the code I use (Sorry for a long...
|
by: AC [MVP MCMS] |
last post by:
Any pointers on how to (1) read a Base64 encoded string from a text file
and (2) write it to a binary file?
I have a ton of files that are being generated from a legacy system. Each
file contains a (1) content type one one line, a (2) filename, and (3) the
encoding type (seems to always be Base64, followed by the encoded string.
A process will be to read the content type and filename, then create a new
binary file and write out the...
|
by: Tibby |
last post by:
I need to read/write not only text files, but binary as well. It seems like on binary files, it doesn't right the last 10% of the file.
--
Thanks
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.538 / Virus Database: 333 - Release Date: 11/10/2003
|
by: tim |
last post by:
I have a multi-dimensional byte array,
private someArray(,,) as byte
and it's huge
redim someArray(100,640,480,3)
after populating the array, I write it to a text file to
save it. (so I don't run out of memory). I will retrieve
from the file later.
What I do is use streamwriter.write and streamreader.read
| |
by: RyanS09 |
last post by:
Hello-
I am trying to write a snippet which will open a text file with an
integer on each line. I would like to read the last integer in the
file. I am currently using:
file = fopen("f.txt", "r+");
fseek(file, -2, SEEK_END);
fscanf(file, "%d", &c);
this works fine if the integer is only a single character. When I get
into larger numbers though (e.g. 502) it only reads in the 2. Is there
|
by: =?Utf-8?B?VGhvbWFzWg==?= |
last post by:
Hi,
Is it possible to read a file in reverse and only get the last 100 bytes in
the file without reading the whole file from the begining? I have to get info
from files that are in the last 100 bytes of the file and some of these files
are 600Mb -1 GB in size. I am getting "outofMemory.." exceptions on the
largest files and the other files take "forever" to get the last 100 bytes.
This is the code I have currently that works with...
|
by: chance |
last post by:
Hello,
I have a file on disk called TEMP.ZIP and I would like to somehow get
this into a memory stream so I can eventually do this:
row = dataStream.ToArray()
However, I am not sure of the correct way to get it into a memory
stream.
Any help appreciated.
|
by: dm3281 |
last post by:
Hello, I have a text report from a mainframe that I need to parse.
The report has about a 2580 byte header that contains binary information
(garbage for the most part); although there are a couple areas that have
ASCII text that I need to extract. At the end of the 2580 bytes, I can read
the report like a standard text file. It should have CR/LF at the end of
each line.
What is the best way for me to read this report using C#. It is...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
| |
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |