Error of binary reading on dmd 2.067.0
ketmar via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Fri Apr 10 05:43:06 PDT 2015
On Fri, 10 Apr 2015 12:15:58 +0000, MGW wrote:
> I wish to read bytes from a file using the formatted input, but it leads
> to a mistake - std.utf.UTFException at std\stdio.d(2719):
> Invalid UTF-8 sequence.
>
> // only for dmd 2.067.0 import std.stdio;
>
> int main (string[] args) {
> auto nf = "TestFile.txt";
> // I write down a verifying file string s = [65, 225, 67]; File
(nf,
> "w").write(s);
>
> // I try to read a file on bytes File f1 = File(nf, "r");
> ubyte c;
> while(true) {
> f1.readf("%d", &c); if(f1.eof) break;
> writeln(c, " ");
> }
> return 0;
> }
are you insisting on using formatted read? it expects valid UTF-8. but
you can do this instead:
ubyte[1] c;
while (f1.rawRead(c[]).length) {
writeln(c, " ");
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: not available
URL: <http://lists.puremagic.com/pipermail/digitalmars-d-learn/attachments/20150410/aa9efb60/attachment.sig>
More information about the Digitalmars-d-learn
mailing list