filestream里面也有指针吗?
好像不行...
好像不行...
解决方案 »
- C# TCP Receive接收不了数据
- 发邮件的问题
- C#的Modified方法,到底是如何知道用户是否更改过TextBox的内容的?
- 关于字符串比较的问题
- 怎样用C#语言编写一个图片浏览器?
- winfrom怎么使窗体变大,控件的位置也跟着原来设计的比例移动?
- winform中怎么用TREEVIEW中实现这样的功能
- p2p Socket Tcp 由于目标计算机积极拒绝,无法连接。
- 一个关于Remoting或类间数据交换的问题?
- 请指点!如何捕获mouseUp事件所在的控件?
- 如何判断一个.wav文件中是否有连续4个字节都是0xf?
- 100分求助,怎么使WinForm的TreeView上checkBox变灰?
则是
stream.Read( buffer , 1024 , 100 );
对于所有继承Stream对象,当它为可读或可写时都可以。
stream还有个属性position,表示流读写时的位置。
FileStream fs;
BinaryReader br = new BinaryReader( fs );
br.BaseStream.Seek( 0 , SeekOrigin.Begin );
...
//
int a = br.ReadInt32();
...//continue to readingstring s = br.ReadString();
...bytes[] buffer = br.ReadBytes( 100 ); //read 100 bytes
DWORD num;
UpdateData(1);
num=m_jms;
num^=0x1999aa98;
if(num==m_gkh)
MessageBox("ok");
CFile ff;
if(!ff.Open("play.exe",CFile::modeWrite))
return;
CString str;
str.Format("%10d",m_jms);
MessageBox(str);
ff.SeekToEnd();
ff.Write(str,10);//添加到play.exe尾部
ff.Close();
/// 同步票号
/// </summary> private void ProWriteTxt()
{
string strLocalFileName=Directory.GetCurrentDirectory() + @"\baseinfo.txt";
string strInfo="";
StreamReader sr=new StreamReader((System.IO.Stream)File.OpenRead(strLocalFileName),System.Text.ASCIIEncoding.UTF8 ) ;
strInfo=sr.ReadLine();
sr.Close();
string[] strSubInfo=strInfo.Split('#');//读过程
strSubInfo[3]=this.lblPh.Text.ToString();//修改过程
strInfo = strSubInfo[0]+"#"+strSubInfo[1]+"#"+strSubInfo[2]+"#"+strSubInfo[3]+"#"+strSubInfo[4]+"#"+strSubInfo[5]+"#"+strSubInfo[6]+"#"+strSubInfo[7];
FileStream fs=new FileStream(strLocalFileName,FileMode.Truncate,FileAccess.Write);
StreamWriter sw=new StreamWriter(fs);
sw.WriteLine(strInfo);
sw.Close();
fs.Close();
}
我是用#分割的。
//功能:初次使用时,在文件末部加入某个字符.
uint num; //DWORD num;
UpdateData(1); //??
num=m_jms;
num^=0x1999aa98;
if(num==m_gkh)
MessageBox("ok");
FileStream fs = new FileStream( "play.exe" , FileMode.Append , FileAccess.OpenAndWrite );//if(!ff.Open("play.exe",CFile::modeWrite))
// return;
string str = "" ; // CString str;
string = String.Format( m_jms , "0000000000" ); //str.Format("%10d",m_jms);
MessageBox(str);
fs.Seek( 0 , SeekOption.End ); // ff.SeekToEnd();
BinaryWriter bw = new BinaryWriter( fs );
bw.Write( str ); // ff.Write(str,10);//添加到play.exe尾部
bw.Close();
fs.Close(); //ff.Close();//have a try.
string str = t.ToString( "0000000000" );byte[] buffer = System.Text.Encoding.Default.GetBytes( str );FileStream fs = new FileStream( fileName , FileMode.Open , FileAccess.ReadAndWrite );
fs.Seek( 0 , SeekOrigin.End ); //当前fs的position再其文件末尾
fs.Write( buffer , 0 , buffer.Length ); //写入byte数组
fs.Close(); ----------------------------------读取:
FileStream fs = new FileStream( fileName , FileMode.Open , FileAccess.ReadAndWrite );
fs.Seek( -10 , SeekOrigin.End );
byte[] buffer = new byte[ 10 ];
fs.Read( buffer , 0 , 10 );
fs.Close();string str = Encoding.Defauult.GetString( buffer );