當前位置:編程學習大全網 - 網站源碼 - 怎樣把文件轉換成二進制形式的文本文件?

怎樣把文件轉換成二進制形式的文本文件?

好吧妳不需要工具的話那我直接用C#的源代碼寫壹下。

public?void?write010File(string?filepath)

{

FileStream?fs?=?new?FileStream(filepath,?FileMode.Open,?FileAccess.Read);

StreamWriter?sw?=?new?StreamWriter("out.txt");

byte[]?buffer?=?new?byte[2048];

int?word?=?0;

while?((word?=?fs.Read(buffer,?0,?buffer.Length))?>?0)

{

//這裏將讀入內存的數據使用二進制寫出

for?(int?i?=?0;?i?<?word;?i++)

{

sw.Write(Convert.ToString(buffer[i],?2));

}

}

sw.Close();

fs.Close();

}

將文件路徑傳入就行了,他會轉換為二進制然後輸出到out.txt中。

  • 上一篇:什麽叫 -O2編譯
  • 下一篇:轉轉支付手續費是什麽意思
  • copyright 2024編程學習大全網