Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9257023
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T12:06:31+00:00 2026-06-18T12:06:31+00:00

I have the following code: LZW lzw = new LZW(); int[] a = lzw.Encode(imageBytes);

  • 0

I have the following code:

LZW lzw = new LZW();
int[] a = lzw.Encode(imageBytes);

FileStream fs = new FileStream("image-text-16.txt", FileMode.Append);
BinaryWriter w = new BinaryWriter(fs);

for (int i = 0; i < a.Length; i++)
{
   w.Write(a[i]);

}

w.Close();
fs.Close();

How to read array elements from the file? I tried several ways. For example, I wrote the length of the array to the file, and I tried to read the number. However, I had failed.

Note. I need to get the int array.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T12:06:32+00:00Added an answer on June 18, 2026 at 12:06 pm

    Are you looking for this:

    var bytes = File.ReadAllBytes(@"yourpathtofile");
    

    Or more something like:

            using (var filestream = File.Open(@"C:\apps\test.txt", FileMode.Open))
            using (var binaryStream = new BinaryReader(filestream))
            {
                for (var i = 0; i < arraysize; i++)
                {
                    Console.WriteLine(binaryStream.ReadInt32());
                }
            }
    

    Or, a small example with unit tests:

    Create a binary file with integers…

        [Test]
        public void WriteToBinaryFile()
        {
            var ints = new[] {1, 2, 3, 4, 5, 6, 7};
    
            using (var filestream = File.Create(@"c:\apps\test.bin"))
            using (var binarystream = new BinaryWriter(filestream))
            {
                foreach (var i in ints)
                {
                    binarystream.Write(i);
                }
            }
        }
    

    And a small example test of reading from a binary file

        [Test]
        public void ReadFromBinaryFile()
        {
            // Approach one
            using (var filestream = File.Open(@"C:\apps\test.bin", FileMode.Open))
            using (var binaryStream = new BinaryReader(filestream))
            {
                var pos = 0;
                var length = (int)binaryStream.BaseStream.Length;
                while (pos < length)
                {
                    var integerFromFile = binaryStream.ReadInt32();
                    pos += sizeof(int);
                }
            }
        }
    

    Another approach of reading from binary file

        [Test]
        public void ReadFromBinaryFile2()
        {
            // Approach two
            using (var filestream = File.Open(@"C:\apps\test.bin", FileMode.Open))
            using (var binaryStream = new BinaryReader(filestream))
            {
                while (binaryStream.PeekChar() != -1)
                {
                    var integerFromFile = binaryStream.ReadInt32();
                }
            }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have following code on my site: backgroundImages[bg_img_path_b]=new Image(); backgroundImages[bg_img_path_b].src = bg_img_path_b; backgroundImages[bg_img_path_b].loaded=loading; //jQuery(backgroundImages[lastImage]).unbind('load.backgroundImages');
I have following code snippet in c# List<int> list = new List<int>() { 1,
I have following code to read a file StreamReader str = new StreamReader(File.Open(fileName, FileMode.Open,
I have following code for loading image from url in xml parsing endElement method
I have following code public interface IDummy<TType> where TType : new() { } public
I have following code: class Program { static AutoResetEvent objAuto = new AutoResetEvent(false); static
I have following code in my page: var myVar= Entity.SetName .Where(p => int.Parse(p.ID) >=
I have following code to serialize my data into a file: out = new
I have following code var res = from c in model.Data select new object[]
I have following code in VS2008 If Linq.Enumerable.Contains(Of String)(selectedUsersRoles, RoleCheckBox.Text) Then RoleCheckBox.Checked = True

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.