Phobos packages a bit confusing

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Sat Dec 5 09:37:41 PST 2009


retard wrote:
> Mon, 30 Nov 2009 04:51:19 +0000, dsimcha wrote:
>> By
>> far the two most important pieces of I/O functionality I need are:
>>
>> 1.  Read a text file line-by-line.
> 
> foreach (line; new Lines!(char) (new File ("foobar.txt")))
>   Cout (line).newline;
> }
> 
>> 2.  Read a whole file into an array of bytes.
> 
> new File("foobar.bin").read()
> 
> 
> Java isn't that bad IMO - you just have to remember the buffer:
> 
> BufferedReader input = new BufferedReader(new FileReader("foo"));
> try {
>   String line = null;
> 
>   while (( line = input.readLine()) != null) {
>   }
> }
> finally {
>   input.close();
> }

Wouldn't you need a try/finally around the D code too?

Andrei



More information about the Digitalmars-d mailing list