Hi
I'm not shure to be in the right section...
I have this code :
try
stream.WriteBuffer(bytesData[0], length(bytesData));
stream.SaveToFile('FileNameAndDirectory');
finally
stream.Free;
Everything goes well except the fact that it doesn't append to file
it rewrites the file everytimes...
Can someone tell me how to append binary?
Thanks
Remy wrote:
> Basically yes, though the directory separator can be different. Some
> platforms use '\', some use '/' instead. You can use the
> TPath.DirectorySeparatorChar property to figure it out:
>
> http://docwiki.embarcadero.com/Libraries/XE7/en/System.IOUtils.TPath.DirectorySeparatorChar
>
> Or better, use TPath.Combine() to create your path strings:
>
> http://docwiki.embarcadero.com/Libraries/XE7/en/System.IOUtils.TPath.Combine
Also, there are several other methods of TPath for locating special folders
on each platform:
http://docwiki.embarcadero.com/RADStudio/XE7/en/Standard_RTL_Path_Functions_across_the_Supported_Target_Platforms
--
Remy Lebeau (TeamB)
Pierre wrote:
> What do I write for ipod, android, ipad and mac instead of
> 'c:\directory\fileName'
>
> is it the same thing but only the directory is changing?
Basically yes, though the directory separator can be different. Some platforms
use '\', some use '/' instead. You can use the TPath.DirectorySeparatorChar
property to figure it out:
http://docwiki.embarcadero.com/Libraries/XE7/en/System.IOUtils.TPath.DirectorySeparatorChar
Or better, use TPath.Combine() to create your path strings:
http://docwiki.embarcadero.com/Libraries/XE7/en/System.IOUtils.TPath.Combine
> Or maybe all this fileStream won't work in all the situations?
Yes, it will work just fine.
--
Remy Lebeau (TeamB)
Works just fine!!!
While I have you...
What do I write for ipod, android, ipad and mac instead of 'c:\directory\fileName'
is it the same thing but only the directory is changing?
Or maybe all this fileStream won't work in all the situations?
Thanks :)
Pierre wrote:
> Everything goes well except the fact that it doesn't append to
> file it rewrites the file everytimes...
That is how all SaveToFile() methods are designed to work. They always create
a new file.
> Can someone tell me how to append binary?
Use SaveToStream() instead to save the stream to a separate TFileStream, eg:
{code}
stream := ...;
try
stream.WriteBuffer(bytesData[0], length(bytesData));
stream.Position := 0;
fstream := TFileStream.Create('FileNameAndDirectory', fmOpenReadWrite or
fmShareDenyWrite);
try
fStream.Seek(0, soEnd);
stream.SaveToStream(fStream);
finally
fstream.Free;
end;
finally
stream.Free;
end;
{code}
In which case, you could just eliminate your original stream altogether and
write directly to the TFileStream instead:
{code}
stream := TFileStream.Create('FileNameAndDirectory', fmOpenReadWrite or fmShareDenyWrite);
try
stream.Seek(0, soEnd);
stream.WriteBuffer(bytesData[0], length(bytesData));
finally
stream.Free;
end;
{code}
--
Remy Lebeau (TeamB)