use System.IO.FileStream class, it has Seek/Read/Write method, see
FileStream : Read or Write Data Streams
http://www.c-sharpcorner.com/1/filestream.asp
FileStream : Read or Write Data Streams
http://www.c-sharpcorner.com/1/filestream.asp
调试欢乐多
using System;class MainClass
{
private static int BUFFERSIZE=0x100;
public static void Main(string[] args)
{
//Console.WriteLine("Hello World!");
save("/home/cao/in.txt", "/home/cao/out.txt");
}
static void save(string strInFileName, string strOutFileName)
{
System.IO.Stream fpIn=null;
System.IO.Stream fpOut=null;
long iRemainder;
int pRead, pWrite, iCount, i, j;
byte[] buf=new byte[BUFFERSIZE];
try
{
fpIn=System.IO.File.OpenRead(strInFileName);
}
catch(System.Exception ex)
{
Console.WriteLine("cannot open in file.");
return;
}
try
{
fpOut=System.IO.File.OpenWrite(strOutFileName);
}
catch(System.Exception ex)
{
Console.WriteLine("cannot open out file");
return;
}
iRemainder=fpIn.Length;
while(iRemainder>0)
{
iCount=fpIn.Read(buf, 0, BUFFERSIZE);
pRead=pWrite=0;
for(i=0;i<iCount;i++)
{
if((buf[pRead] != 0xa) && (buf[pRead] !=0xd))
{
buf[pWrite]=buf[pRead];
pWrite++;
}
pRead++;
}
fpOut.Write(buf, 0, pWrite);
iRemainder-=iCount;
}
fpIn.Close();
fpOut.Close();
}//save
}//class
{
private static int BUFFERSIZE=0x100;
public static void Main(string[] args)
{
//Console.WriteLine("Hello World!");
save("/home/cao/in.txt", "/home/cao/out.txt");
}
static void save(string strInFileName, string strOutFileName)
{
System.IO.Stream fpIn=null;
System.IO.Stream fpOut=null;
long iRemainder;
int pRead, pWrite, iCount, i, j;
byte[] buf=new byte[BUFFERSIZE];
try
{
fpIn=System.IO.File.OpenRead(strInFileName);
}
catch(System.Exception ex)
{
Console.WriteLine("cannot open in file.");
return;
}
try
{
fpOut=System.IO.File.OpenWrite(strOutFileName);
}
catch(System.Exception ex)
{
Console.WriteLine("cannot open out file");
return;
}
iRemainder=fpIn.Length;
while(iRemainder>0)
{
iCount=fpIn.Read(buf, 0, BUFFERSIZE);
pRead=pWrite=0;
for(i=0;i<iCount;i++)
{
if((buf[pRead] != 0xa) && (buf[pRead] !=0xd))
{
buf[pWrite]=buf[pRead];
pWrite++;
}
pRead++;
}
fpOut.Write(buf, 0, pWrite);
iRemainder-=iCount;
}
fpIn.Close();
fpOut.Close();
}//save
}//class
#include<math.h>
#define BUFFERSIZE 0x100FILE *fp1,*fp2,*fp3,*fp4;
void save(strInFileName,strOutFileName)
char *strInFileName,*strOutFileName;
{ FILE *fpIn,*fpOut;
long int iFileLength;
long int iCount;
long int iRemainder;
long int i,j;
int pRead,pWrite;
char buf[BUFFERSIZE]; if((fpIn=fopen(strInFileName,"rb"))==NULL)
{ printf("connot open In file\n");
exit(0);
}
if((fpOut=fopen(strOutFileName,"wb"))==NULL)
{ printf("connot open out file\n");
exit(0);
} fseek(fpIn,0,SEEK_END);
iFileLength = ftell(fpIn);
fseek(fpIn,0,SEEK_SET); iCount = iFileLength / BUFFERSIZE;
iRemainder = iFileLength % BUFFERSIZE;
for(i=0;i<iCount;i++) {
fread(buf,sizeof(char),BUFFERSIZE,fpIn);
pRead=0;
pWrite=0;
for( j=0;j<BUFFERSIZE;j++) {
if( buf[pRead]!=0xa && buf[pRead]!=0xd ) {
buf[pWrite]=buf[pRead];
pWrite++;
}
pRead++;
}
fwrite(buf,sizeof(char),pWrite,fpOut);
} fread(buf,sizeof(char),iRemainder,fpIn);
pRead=0;
pWrite=0;
for( j=0;j<iRemainder;j++) {
if( buf[pRead]!=0xa && buf[pRead]!=0xd ) {
buf[pWrite]=buf[pRead];
pWrite++;
}
pRead++;
}
fwrite(buf,sizeof(char),pWrite,fpOut);
fclose(fpIn);
fclose(fpOut);
return;
}
long int ff (a,b,c,d)
char a,b,c,d;
{
long int tt;
if(a>96) a=a-87;
else if(a>60) a=a-55;
else a=a-48;
if(b>96) b=b-87;
else if(b>60) b=b-55;
else b=b-48;
if(c>96) c=c-87;
else if(c>60) c=c-55;
else c=c-48;
if(d>96) d=d-87;
else if(d>60) d=d-55;
else d=d-48; tt=(long)c*16+(long)d+(long)a*4096+(long)b*256; if(tt<32768) tt=tt; else tt=tt-65536;
return (tt);
}
main(int argc,char*argv[] )
{long timer[20];
int i,kl,kkl,n,vsp;
float vsp1,ps1,bn1,vsp2,ps2,bn2,vsp3,ps3,bn3;
char *dats=".dat";
char buffer[128],f,buff[100],newname[30],newaa[20],time[10];
if(argc!=4)
{ printf("you forgot to enter a filename\n");
exit(0);
}if((fp1=fopen("zd8bxxx.ddd","wb+"))==NULL)
{ printf("input file open file\n");
exit(0);
}
if((fp2=fopen(argv[2],"ab"))==NULL)
{ printf("output1 file open file\n");
exit(0);
}
if((fp3=fopen(argv[3],"ab"))==NULL)
{ printf("output2 file open file\n");
exit(0);
}
save(argv[1],"zd8bxxx.ddd");
fread(&time,sizeof(char),8,fp1);
for(i=2;i<8;i++)
newname[i-1]=time[i];
newname[0]='d';
newname[7]=0;
for(i=0;i<7;i++)
newaa[i]=newname[i+3];
strcat(newname,dats);
if((fp4=fopen(newname,"wb"))==NULL)
{ printf("output file open fail\n");
exit(0);
} fread(&timer,sizeof(long int),14,fp1);
for(i=0;i<24;i++)
{
fread(&buffer,sizeof(char),48,fp1); vsp=ff(buffer[0],buffer[1],buffer[2],buffer[3]);
vsp1=(float)vsp/10;
ps1=(float)ff(buffer[4],buffer[5],buffer[6],buffer[7])/100;
bn1=(float)ff(buffer[8],buffer[9],buffer[10],buffer[11])/100;
vsp2=(float)ff(buffer[16],buffer[17],buffer[18],buffer[19])/10;
ps2=(float)ff(buffer[20],buffer[21],buffer[22],buffer[23])/100;
bn2=(float)ff(buffer[24],buffer[25],buffer[26],buffer[27])/100;
vsp3=(float)ff(buffer[32],buffer[33],buffer[34],buffer[35])/10;
ps3=(float)ff(buffer[36],buffer[37],buffer[38],buffer[39])/100;
bn3=(float)ff(buffer[40],buffer[41],buffer[42],buffer[43])/100; fprintf(fp2,"%4s%5d%8.1f%7.2f%7.2f%8.1f%7.2f%7.2f%8.1f%7.2f%7.2f\n"
,newaa,i,vsp1,ps1,bn1,vsp2,ps2,bn2,vsp3,ps3,bn3);
fprintf(fp4,"%4s%5d%8.1f%7.2f%7.2f%8.1f%7.2f%7.2f%8.1f%7.2f%7.2f\n"
,newaa,i,vsp1,ps1,bn1,vsp2,ps2,bn2,vsp3,ps3,bn3);
}
fread(&buff,sizeof(char),48,fp1);
fread(&buff,sizeof(char),48,fp1);
vsp1=(float)ff(buff[0],buff[1],buff[2],buff[3])/10;
ps1=(float)ff(buff[4],buff[5],buff[6],buff[7])/100;
bn1=(float)ff(buff[8],buff[9],buff[10],buff[11])/100;
vsp2=(float)ff(buff[16],buff[17],buff[18],buff[19])/10;
ps2=(float)ff(buff[20],buff[21],buff[22],buff[23])/100;
bn2=(float)ff(buff[24],buff[25],buff[26],buff[27])/100;
vsp3=(float)ff(buff[32],buff[33],buff[34],buff[35])/10;
ps3=(float)ff(buff[36],buff[37],buff[38],buff[39])/100;
bn3=(float)ff(buff[40],buff[41],buff[42],buff[43])/100; fprintf(fp3,"%6s%8.1f%8.2f%8.2f%8.1f%8.2f%8.2f%8.1f%8.2f%8.2f\n",
newaa,vsp1,ps1,bn1,vsp2,ps2,bn2,vsp3,ps3,bn3);
fclose(fp1);
fclose(fp2);
fclose(fp3);
fclose(fp4);
}