www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - std.file.read || writefln

reply MM <MM_member pathlink.com> writes:
Why do I get:

An exception occured: 4invalid UTF-8 sequence

From:
http://www.docwiki.net/view.php?pageid=150

The content of the file doesn't matter afaik :)
Just some simple .txt file in ansi or unicode.. (windowsxp)
Jun 16 2006
parent reply "Jarrett Billingsley" <kb3ctd2 yahoo.com> writes:
"MM" <MM_member pathlink.com> wrote in message 
news:e6v3hk$b1u$1 digitaldaemon.com...
 Why do I get:

 An exception occured: 4invalid UTF-8 sequence

 From:
 http://www.docwiki.net/view.php?pageid=150

 The content of the file doesn't matter afaik :)
 Just some simple .txt file in ansi or unicode.. (windowsxp)
That's an interesting bug. Notice the "MZ" at the beginning of your output - that's the header for an EXE file. What's going on is that args[0] is actually the name of the running program - that is, if you compile this program as "test.d", the program will be "test.exe" - so when you type in test something.txt On the command line, the args[][] array is populated with: ["test.exe", "something.txt"] So args[0] is the name of the program. Change it to args[1], and it should work. And update that wiki article while you're at it ;)
Jun 16 2006
next sibling parent reply MM <MM_member pathlink.com> writes:
Change it to args[1], and it should work.  And update that wiki article 
while you're at it ;) 
Ay sir, I will as soon as you tell me what the best way to read raw data is.. from the beginning, byte for byte, till end of file :D (while I'm waiting for my registration email to come to me :) and thx
Jun 16 2006
parent reply "Derek Parnell" <derek psych.ward> writes:
On Sat, 17 Jun 2006 08:02:49 +1000, MM <MM_member pathlink.com> wrote:

 Change it to args[1], and it should work.  And update that wiki article
 while you're at it ;)
Ay sir, I will as soon as you tell me what the best way to read raw data is.. from the beginning, byte for byte, till end of file :D (while I'm waiting for my registration email to come to me :) and thx
It wasn't the reading that caused the crash but trying to write the raw data as if it was char[] (UTF8). You have to treat raw data as ubyte[] or byte[] depending on how you will use it. -- Derek Parnell Melbourne, Australia
Jun 16 2006
parent reply MM <MM_member pathlink.com> writes:
It wasn't the reading that caused the crash but trying to write the raw  
data as if it was char[] (UTF8). You have to treat raw data as ubyte[] or  
byte[] depending on how you will use it.

-- 
Derek Parnell
Melbourne, Australia
Somehow my last post got lost... here it is again :) I wanted to read a file without having to put the whole thing in mem.. Or doen't read do this? If there is some way to read a file byte for byte how do I know end_of_file? (I also didn't recieve the registration email from the docwiki... I'll try that again too, although the problem is already corrected :)
Jun 17 2006
parent "Jarrett Billingsley" <kb3ctd2 yahoo.com> writes:
"MM" <MM_member pathlink.com> wrote in message 
news:e71o47$c4v$1 digitaldaemon.com...

 Somehow my last post got lost... here it is again :)
 I wanted to read a file without having to put the whole thing in mem.. Or 
 doen't
 read do this?
 If there is some way to read a file byte for byte how do I know 
 end_of_file?
 (I also didn't recieve the registration email from the docwiki... I'll try 
 that
 again too, although the problem is already corrected :)
Use std.stream.File, or std.stream.BufferedFile. To see if you're at the end of the file, use the .eof() method for either of those.
Jun 17 2006
prev sibling parent Markus Dangl <danglm in.tum.de> writes:
Jarrett Billingsley schrieb:
 "MM" <MM_member pathlink.com> wrote in message 
 news:e6v3hk$b1u$1 digitaldaemon.com...
 Why do I get:

 An exception occured: 4invalid UTF-8 sequence

 From:
 http://www.docwiki.net/view.php?pageid=150

 The content of the file doesn't matter afaik :)
 Just some simple .txt file in ansi or unicode.. (windowsxp)
That's an interesting bug. Notice the "MZ" at the beginning of your output - that's the header for an EXE file. What's going on is that args[0] is actually the name of the running program - that is, if you compile this program as "test.d", the program will be "test.exe" - so when you type in test something.txt On the command line, the args[][] array is populated with: ["test.exe", "something.txt"] So args[0] is the name of the program. Change it to args[1], and it should work. And update that wiki article while you're at it ;)
This is a bad example, i corrected it. Using writefln for binary data isn't a thing you want to do normally ;)
Jun 17 2006