E
Ebrahim
I am trying to copy a file using BinaryReader / Writer .
I started with this mp3 .. it was ~640 kb . BUt THe output file that
is created by my code is only ~320 kb ??
heres the code
--------------------------------------------------------------------------------
try
{
//System.Net.Sockets.TcpClient t = new
System.Net.Sockets.TcpClient("localhost",15000);
//BinaryWriter outs = new BinaryWriter(t.GetStream());
BinaryReader fs = new
BinaryReader((Stream)File.Open(@"c:\\dumb.mp3",FileMode.Open));
BinaryWriter outf = new
BinaryWriter((Stream)File.Open(@"c:\dummy.mp3",FileMode.OpenOrCreate,FileAccess.Write));
byte [] cbuf = new byte[1024];
this.progressBar1.Minimum = 0;
this.progressBar1.Maximum = 100;
MessageBox.Show(fs.BaseStream.Length.ToString());
while(fs.BaseStream.Position < fs.BaseStream.Length)
{
fs.Read(cbuf , 0 , 1024);
fs.BaseStream.Position+=1024;
outf.Write(cbuf,0,cbuf.Length);
//outf.Flush();
this.progressBar1.Value =
(int)(fs.BaseStream.Position/fs.BaseStream.Length)*100;
//outs.Write(cbuf,0,1024);
Application.DoEvents();
}
outf.Flush();
fs.Close();
outf.Close();//outs.Close();
//t.Close();
}
catch(Exception ee)
{
MessageBox.Show(ee.Message);
}
I started with this mp3 .. it was ~640 kb . BUt THe output file that
is created by my code is only ~320 kb ??
heres the code
--------------------------------------------------------------------------------
try
{
//System.Net.Sockets.TcpClient t = new
System.Net.Sockets.TcpClient("localhost",15000);
//BinaryWriter outs = new BinaryWriter(t.GetStream());
BinaryReader fs = new
BinaryReader((Stream)File.Open(@"c:\\dumb.mp3",FileMode.Open));
BinaryWriter outf = new
BinaryWriter((Stream)File.Open(@"c:\dummy.mp3",FileMode.OpenOrCreate,FileAccess.Write));
byte [] cbuf = new byte[1024];
this.progressBar1.Minimum = 0;
this.progressBar1.Maximum = 100;
MessageBox.Show(fs.BaseStream.Length.ToString());
while(fs.BaseStream.Position < fs.BaseStream.Length)
{
fs.Read(cbuf , 0 , 1024);
fs.BaseStream.Position+=1024;
outf.Write(cbuf,0,cbuf.Length);
//outf.Flush();
this.progressBar1.Value =
(int)(fs.BaseStream.Position/fs.BaseStream.Length)*100;
//outs.Write(cbuf,0,1024);
Application.DoEvents();
}
outf.Flush();
fs.Close();
outf.Close();//outs.Close();
//t.Close();
}
catch(Exception ee)
{
MessageBox.Show(ee.Message);
}