TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Ram Prasad
NA
326
18.4k
Reading alphanumeric data from text file
Jun 7 2020 7:14 PM
I am using the code below to read binary data from text file and divide it into small chunks. I want to do the same with a text file with alphanumeric data which is obviously not working with the binary reader. Which reader would be best to achieve that stream,string or text and how to implement that in the following code?
public
static
IEnumerable < IEnumerable <
byte
>> ReadByChunk(
int
chunkSize) {
IEnumerable <
byte
> result;
int
startingByte = 0;
do
{
result = ReadBytes(startingByte, chunkSize);
startingByte += chunkSize;
yield
return
result;
}
while
(result.Any());
}
public
static
IEnumerable <
byte
> ReadBytes(
int
startingByte,
int
byteToRead) {
byte
[] result;
using
(FileStream stream = File.Open(@
"C:\Users\file.txt"
, FileMode.Open, FileAccess.Read,
FileShare.Read))
using
(BinaryReader reader =
new
BinaryReader(stream)) {
int
bytesToRead = Math.Max(Math.Min(byteToRead, (
int
) reader.BaseStream.Length -
startingByte), 0);
reader.BaseStream.Seek(startingByte, SeekOrigin.Begin);
result = reader.ReadBytes(bytesToRead);
}
return
result;
}
Reply
Answers (
1
)
Audio length calculation
Replace starting and ending characters of a string