Load entire file, as a char array.

Chris Katko ckatko at gmail.com
Mon Sep 3 04:30:10 UTC 2018


On Monday, 3 September 2018 at 03:19:39 UTC, Neia Neutuladh wrote:
> On Monday, 3 September 2018 at 03:04:57 UTC, Chris Katko wrote:
>> This should be simple? All I want to do is load an entire 
>> file, and access individual bytes. The entire thing. I don't 
>> want to have know the file size before hand, or "guess" and 
>> have a "maximum size" buffer.
>>
>> So far, all google searches for "dlang binary file read" end 
>> up not working for me.
>>
>> Thank you.
>
> http://dpldocs.info/experimental-docs/std.file.read.1.html
>
> import std.file : read;
> auto bytes = read("filename");
>
> This gives you a void[], which you can cast to ubyte[] or 
> char[] or whatever you need.

That works great! I thought all file i/o had to through the File 
class.


More information about the Digitalmars-d-learn mailing list