www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Error of binary reading on dmd 2.067.0

reply "MGW" <mgw yandex.ru> writes:
I wish to read bytes from a file using the formatted input, but 
it leads to a mistake - std.utf.UTFException 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;
}
Apr 10 2015
parent reply ketmar <ketmar ketmar.no-ip.org> writes:
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 std\stdio.d(2719):
 Invalid UTF-8 sequence.
=20
 // only for dmd 2.067.0 import std.stdio;
=20
 int main (string[] args) {
 	auto nf =3D "TestFile.txt";
 	// I write down a verifying file string s =3D [65, 225, 67]; File
(nf,
 	"w").write(s);
=20
 	// I try to read a file on bytes File f1 =3D 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=20 you can do this instead: ubyte[1] c; while (f1.rawRead(c[]).length) { writeln(c, " "); } =
Apr 10 2015
parent "MGW" <mgw yandex.ru> writes:
Many thanks!
Apr 10 2015