Languages

file

Reading binary data with GIO

0
Your rating: None
static int main (string[] args) {
    try {
 
        // Reference a BMP image file
        var file = File.new_for_uri ("http://wvnvaxa.wvnet.edu/vmswww/images/test8.bmp");
//      var file = File.new_for_path ("sample.bmp");
 
        // Open file for reading
        var file_stream = file.read (null);
        var data_stream = new DataInputStream (file_stream);
        data_stream.set_byte_order (DataStreamByteOrder.LITTLE_ENDIAN);
 
        // Read the signature
        uint16 signature = data_stream.read_uint16 (null);
        if (signature != 0x4d42) {
            stderr.prin

Simple file operations with GIO

0
Your rating: None
static int main (string[] args) {
    try {
 
        // Reference a local file name
        var file = File.new_for_path ("samplefile.txt");
 
        {
            // Create a new file with this name
            var file_stream = file.create (FileCreateFlags.NONE, null);
 
            // Test for the existence of file
            if (file.query_exists (null)) {
                stdout.printf ("File successfully created.\n");
            }
 
            // Write text data to file
            var data_stream = new DataOutputStream (file_stream);
            data_stream.put_string (

Reading text file line by line with GIO

0
Your rating: None
static int main (string[] args) {
    // A reference to our file
    var file = File.new_for_path ("data.txt");
 
    if (!file.query_exists (null)) {
        stderr.printf ("File '%s' doesn't exist.\n", file.get_path ());
        return 1;
    }
 
    try {
        // Open file for reading and wrap returned FileInputStream into a
        // DataInputStream, so we can read line by line
        var in_stream = new DataInputStream (file.read (null));
        string line;
        // Read lines until end of file (null) is reached
        while ((line = in_stream.read_line (null, null)
Syndicate content