How to read all data from .lbl file

萝らか妹 提交于 2019-12-13 04:32:48

问题


I have One lable file which contain barcode sticker n its values, I want to read that file and copy that file, So ,I am using below function. Its work, but its very time consuming..!! So, do u have any idea how to read all the data of lbl file rather than read data bit by bit which i am doing. So , i can increse my performance.

    public void storeLbl(string path)
    {

            lblData = ""; 


            using (BinaryReader b = new BinaryReader(File.Open(path, FileMode.Open)))
            {

                int pos = 0;


                int length = (int)b.BaseStream.Length;
                while (pos < length)
                {

                    int v = b.ReadInt32();
                    if (lblData.ToString() == "")
                    {
                        lblData = v.ToString();
                    }
                    else
                    {
                        lblData = lblData + "," + v.ToString(); // Store Lbl Data in database


                    }

                    pos += sizeof(int);

                }
                b.Close(); 
    }   
   }

Second Function Which copy .lbl file with help from database value //getting lblData value from Database

public void getLbl()
{

            string[] store = lblData .Split(',');

            int length = store.Length;
            storeval = new int[length];
            for (int i = 0; i < length; i++)
            {
                storeval[i] = Convert.ToInt32(store[i]);

            }


            using (BinaryWriter w = new BinaryWriter(NewPath, FileMode.Create)))// Create Copy of .lbl file
            {
                for (int i = 0; i < length; i++)
                {
                    w.Write(storeval[i]);

                    Console.WriteLine(storeval[i]);

                }
                w.Close();  

            }
    }

回答1:


You can use

byte[] allData = binaryreader1.ReadBytes(int.MaxValue); 

to read all the data.

And write that byte array directly to a binarywriter.




回答2:


With help of @cadsjo Answer I got the Solution, Now My Function is!!

using (BinaryReader b = new BinaryReader(File.Open("Original file Path", FileMode.Open))) {

            int length = (int)b.BaseStream.Length;
            byte[] allData = b.ReadBytes(length);

            using (BinaryWriter w = new BinaryWriter(File.Open("New File Path", FileMode.Create)))
            {

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

                }

            }
        }


来源:https://stackoverflow.com/questions/18742200/how-to-read-all-data-from-lbl-file

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!