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
Jay S
NA
230
59.4k
Binaryreader returning wrong position
Nov 24 2016 5:50 AM
Hello.
I am reading in a file as a stream through a binaryreader. I read in a number of bytes but when checking the basestream position its a lot further a long than it should be.
Code example:
public
void
MainLoader()
{
FileStream input = System.IO.File.Open(path, System.IO.FileMode.Open);
BinaryReader binaryReader =
new
BinaryReader(input, Encoding.GetEncoding(1252));
byte
[] bytes = binaryReader.ReadBytes(256);
// 256 bytes
binaryReader.ReadInt32();
//4 bytes
binaryReader.ReadInt32();
//4 bytes
binaryReader.ReadInt16();
//2 bytes
binaryReader.ReadInt32();
//4 bytes
binaryReader.ReadInt16();
//2 bytes
binaryReader.ReadByte();
// 1 byte
binaryReader.ReadBoolean();
// 1 byte
binaryReader.ReadByte();
// 1 byte
binaryReader.ReadByte();
// 1 byte
binaryReader.ReadInt16();
//2 bytes
binaryReader.ReadByte();
// 1 byte
binaryReader.ReadBoolean();
// 1 byte
binaryReader.ReadByte();
// 1 byte
binaryReader.ReadByte();
// 1 byte
binaryReader.ReadByte();
// 1 byte
binaryReader.ReadInt16();
//2 bytes
binaryReader.ReadInt16();
//2 bytes
binaryReader.ReadByte();
// 1 byte
//New for 2017
binaryReader.ReadByte();
// 1 byte
binaryReader.ReadByte();
// 1 byte
binaryReader.ReadByte();
// 1 byte
binaryReader.ReadByte();
// 1 byte
// should return 292
var position = binaryReader.BaseStream.Position
binaryReader.Close();
}
Adding up all the read in bytes should be 292, and this should be the stream position too ( I read from the start of the file)
The issue I have is that in fact it returns 4096. I do not understand this, what could be influences this.
I have thought maybe Culture settings, Encoding, or Endians, but I am no sure.
Any thoughts would be great.
Reply
Answers (
0
)
Convert HTML Code Into Image
how to find the city through google api