急!!!在线等待回答
c#或vb.net中,如何二进制写文件?有实例代码更好. 问题点数:100、回复次数:8Top
1 楼angxain(卖女孩的小火财)回复于 2003-09-03 13:42:20 得分 0
這個不知道對你有沒能用哦
DataRow dr = t.Rows.Find(new object[]{intLSH});
byte[] mydata = ((byte[])dr["TZ"]);
FileStream newFile = null;
newFile = new FileStream("aaa.dwg",FileMode.Create);
newFile.Write(mydata,0,mydata.Length);
newFile.Close();Top
2 楼cnhgj(戏子) (没时间练太极)回复于 2003-09-03 13:45:22 得分 0
Structure CustomerRecord
Public OrderNumber As Integer
Public Name As String
Public OrderDate As Date
End Structure
Sub WriteData()
Dim MyRecord As CustomerRecord
Dim RecordNumber As Integer
Dim RecordDate As Date
' 打开文件进行随机访问。
FileOpen(1, "C:\TESTFILE.txt", OpenMode.Binary)
For RecordNumber = 1 To 3 ' 循环 3 次。
MyRecord.OrderNumber = RecordNumber ' 定义 OrderNumber。
MyRecord.OrderDate = RecordDate ' 定义 OrderDate。
MyRecord.Name = "我的姓名" & RecordNumber ' 创建字符串。
FilePut(1, MyRecord) ' 将记录写入文件。
Next RecordNumber
FileClose(1)
End Sub
Top
3 楼Jem(Jem)回复于 2003-09-03 13:51:31 得分 0
换句话说吧,我现在已经有一个字串"145 tghd 为什么",如果想将该字串写进文件中,该怎么处理?(注:该字串中有全角文字)Top
4 楼jjcccc(就这样吧)回复于 2003-09-03 13:52:15 得分 0
FileStream fs=new FileStream(@"test.log",FileMode.Create,FileAccess.Write);
//写入字节
byte theByte=100;
fs.WriteByte(theByte);
//写入字节数组
byte[] theBytes;//实际写入时需要初始化该数组
int nBytes; //实际写入时需要初始化,写入的字节数
fs.Write(theBytes,0,nBytes);Top
5 楼jjcccc(就这样吧)回复于 2003-09-03 13:59:53 得分 0
string s="145 tghd 为什么";
byte[] theBytes=SysTem.Text.Encoding.GetBytes(s);
然后再将之写入文件。Top
6 楼win911(Vincent)回复于 2003-09-03 14:34:43 得分 100
private const string FILE_NAME = @"C:\Documents and Settings\Administrator\桌面\Win Odds.htm";
private const string file_name = @"C:\Documents and Settings\Administrator\桌面\Win.txt";
private void button1_Click(object sender, System.EventArgs e)
{
if (!File.Exists(FILE_NAME))
{
Console.WriteLine("{0} does not exist.", FILE_NAME);
return;
}
//以繁体字的encoding形式读取文件
StreamReader sr = new StreamReader(FILE_NAME,System.Text.Encoding.GetEncoding(950) ,true,200);
//以简体字的encoding写入文件
// StreamWriter sw= new StreamWriter(file_name,false,System.Text.Encoding.GetEncoding(936),200);
String input;
input=sr.ReadToEnd();
RG(input,sr);
Console.WriteLine ("The end of the stream has been reached.");
sr.Close();
}
private void RG(string inputString,System.IO.StreamReader ss)
{
System.Text.RegularExpressions.Regex r;
System.Text.RegularExpressions.Match m;
StreamWriter sw= new StreamWriter(file_name,false,System.Text.Encoding.GetEncoding(936),200);
String input;
input=ss.ReadLine ();
r = new System.Text.RegularExpressions.Regex(">(\\S)([^陣容往績心水推介賠率走勢圖][^(\\<*\\>)]*)<\\S",System.Text.RegularExpressions.RegexOptions.IgnoreCase|System.Text.RegularExpressions.RegexOptions.Compiled );
for (m = r.Match(inputString); m.Success; m = m.NextMatch())
{
sw.WriteLine(m.ToString());
}
sw.Close();
}
以前的一部分代码,没整理,乱了点。
读写文件什么的都在里面了。Top
7 楼Jem(Jem)回复于 2003-09-03 14:34:47 得分 0
谢了,各位Top
8 楼Jem(Jem)回复于 2003-09-03 14:45:20 得分 0
大侠win911(Young),强~~~~~~~~~~~~~~~~~~~~Top




