C# 如何讀取被其他進程佔用的文件

說明:本程序爲讀取exe文件自身的數據。

截圖:


        private void button1_Click(object sender, EventArgs e)
        {
            String fileName = Application.ExecutablePath;
            FileStream fs = new FileStream(fileName, System.IO.FileMode.Open, FileAccess.Read);
            byte[] array = new byte[32];
            int i;
            String numHexStr;
            String lineStr;
            for (i = 0; i < fs.Length / 16; i++)
            {
                fs.Read(array, 0, 16);
                lineStr = string.Format("{0:X8}:", i * 16);
                for (int j = 0; j < 16; j++)
                {
                    numHexStr = string.Format("{0:X2}", array[j]);
                    lineStr += numHexStr + " ";
                }
                textBox1.Text =textBox1.Text + lineStr + Environment.NewLine;
            }
            long mod = fs.Length % 16;
            if (mod > 0)
            {
                lineStr = string.Format("{0:X8}:", i * 16);
                fs.Read(array, 0, (int)mod);
                for (int j = 0; j < mod; j++)
                {
                    numHexStr = string.Format("{0:X2}", array[j]);
                    lineStr += numHexStr + " ";
                }
                textBox1.Text = textBox1.Text + lineStr + Environment.NewLine;
            }
            fs.Close();
        }


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章