Ok. Thanks. I see that it is possible, though the syntax is not what I would call pretty...
...which made me thinking, would it be possible to write something that use the iterator interface for reading lines from a file? I.e. something like:
File f = File.open("path");
foreach (string s in f.readlines()) {
print s;
}
What exactly is an iterator? An interface? Where is it defined?
Regards,
Dov2008/6/8 Frederik <scumm_fredo gmx net>:Dov Grobgeld schrieb:Use GIO instead, it's part of the GLib namespace.
In my efforts to of making sure that I can do simple constructs with the language I tried to read a file line by line.
http://library.gnome.org/devel/gio/stable/
File.read () will give you a FileInputStream which you can decorate as
a DataInputStream, then you can read line by line.
------
File my_file = File.new_for_path ("myfile.data");
DataInputStream in_stream;
try {
in_stream = new DataInputStream (my_file.read (null));
string line;
while (null != (line = in_stream.read_line (null, null))) {
print (line);
}
} catch (Error e) {
critical (e.message);
} finally {
in_stream.close (null);
}
------
You will have to compile with "--pkg gio-2.0". Currently you will get
some warnings about nullable parameters, since they aren't marked yet in the vapi bindings, which you can safely ignore.
Frederik
_______________________________________________
Vala-list mailing list
Vala-list gnome org
http://mail.gnome.org/mailman/listinfo/vala-list