readText fails to open file
Ali Çehreli
acehreli at yahoo.com
Sun Jun 17 01:32:36 PDT 2012
On 06/17/2012 01:21 AM, GreatEmerald wrote:
> This is kind of silly, and I probably missed something, but for some
> reason I can't get any kind of text file opened when using readText from
> std.file. This is what I'm trying to do:
>
> import std.stdio;
> import std.file;
>
> int main(string[] args)
> {
> if (!isFile(args[0]))
> {
> writeln("Error: Input file does not exist or is not a valid file!");
> return 1;
> }
>
> auto LTFFile = chomp(readText(args[0]));
>
> readln();
> return 0;
> }
>
> Nice and simple, right? So I execute it:
>
> > ./LTF2LIP LTF2LIP.d
> std.utf.UTFException at std/utf.d(645): Invalid UTF-8 sequence (at index 1)
>
> And I'm sure that the file is in UTF-8, with LF line endings, without a
> BOM. The same error is thrown when I try any other kind of files. So
> what gives?..
Try args[1]. Your compiled program is surely not UTF-8. ;)
--
D Programming Language Tutorial: http://ddili.org/ders/d.en/index.html
More information about the Digitalmars-d-learn
mailing list