Article View: borland.public.cppbuilder.nativeapi
Article #17117Re: Split file.
From: Remy Lebeau (TeamB)
Date: Wed, 09 Apr 2003 21:46
Date: Wed, 09 Apr 2003 21:46
62 lines
2896 bytes
2896 bytes
"Safari" <Safari@alloymail.com> wrote in message
news:3E9466BC.8060508@alloymail.com...
> 1. I fail to write or complete this code! return me two errors.
> {a. Stream read error.
The only time that can happen is inside TStream::ReadBuffer() when
TStream::Read() returns a value other than the requested amount. Which
makes sense if you are requesting 50000 bytes and it reads fewer (due to end
of file, for example).
The same applies to WriteBuffer() as well - it will throw an exception if
the amount written does not match the amount requested.
You should be calling Read() and Write() instead of ReadBuffer() and
WriteBuffer().
> 2. Your simple code dosn't write any file!, excuse me.
The following code works fine for me:
int iSourceFile = FileOpen("C:\\test.rtf", fmOpenRead |
fmShareDenyWrite);
if( iSourceFile != -1 )
{
BYTE buffer[50000];
int iNum = 1;
do
{
int iRead = FileRead(iSourceFile, buffer, 50000);
if( iRead != -1 )
{
if( iRead == 0 )
break; // finished
AnsiString ext = Format("%.3d", ARRAYOFCONST(( iNum )));
++iNum;
int iNewFile = FileCreate("C:\\test." + ext);
if( iNewFile != -1 )
{
if( FileWrite(iNewFile, buffer, iRead) != iRead )
// an error occured, handle it as needed
FileClose(iNewFile);
}
else
// an error occured, handle it as needed
}
else
// an error occured, handle it as needed
}
while( true );
FileClose(iSourceFile);
}
else
// an error occured, handle it as needed
Gambit
Technical Details
Message-ID:
<3e9494b9$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-03!sn-xit-06!sn-xit-08!supernews.com!priapus.visi.com!news-out.visi.com!petbe.visi.com!newsfeed.wirehub.nl!news.kweb.on.ca!KWeb!newsgroups.borland.com!not-for-mailReferences:
<3E8F1D05.40008@alloymail.com> <3e8f69e0@newsgroups.borland.com> <3E9466BC.8060508@alloymail.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10cc67,8f5102c5a422c5bb X-Google-Attributes: gid10cc67,public X-Google-ArrivalTime: 2003-04-09 14:56:10 PST From: "Remy Lebeau \(TeamB\)" <gambit47@yahoo.com> Newsgroups: borland.public.cppbuilder.nativeapi References: <3E8F1D05.40008@alloymail.com> <3e8f69e0@newsgroups.borland.com> <3E9466BC.8060508@alloymail.com> Subject: Re: Split file. Date: Wed, 9 Apr 2003 14:46:10 -0700 Lines: 64 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1106 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106 NNTP-Posting-Host: 207.175.226.26 Message-ID: <3e9494b9$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1049924793 207.175.226.26 (9 Apr 2003 14:46:33 -0800) Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-03!sn-xit-06!sn-xit-08!supernews.com!priapus.visi.com!news-out.visi.com!petbe.visi.com!newsfeed.wirehub.nl!news.kweb.on.ca!KWeb!newsgroups.borland.com!not-for-mail