我有一个标签文件,其中包含条形码标签及其值,我想读取该文件并复制该文件,所以,我正在使用以下功能。它的工作,但它非常耗时..!! 那么,您是否知道如何读取 lbl 文件的所有数据,而不是像我正在做的那样逐位读取数据。所以,我可以提高我的表现。
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();
}
}
第二个函数在数据库值的帮助下复制.lbl文件//从数据库中获取lblData值
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();
}
}