Sign In Start Free Trial
Account

Add to playlist

Create a Playlist

Modal Close icon
You need to login to use this feature.
  • DART Cookbook
  • Toc
  • feedback
DART Cookbook

DART Cookbook

By : Ivo Balbaert
4 (2)
close
DART Cookbook

DART Cookbook

4 (2)
By: Ivo Balbaert

Overview of this book

If you are a Dart developer looking to sharpen your skills, and get insight and tips on how to put that knowledge into practice, then this book is for you. You should also have a basic knowledge of HTML, and how web applications with browser clients and servers work, in order to build dynamic Dart applications.
Table of Contents (13 chapters)
close
12
Index

Reading and processing a file line by line


Files containing data in the comma separated values (csv) format are structured so that one line contains data about one object, so we need a way to read and process the file line by line. As an example, we use the data file winequality-red.csv, that contains 1,599 sample measurements, 12 data columns, such as pH and alcohol, per sample, separated by a semicolon (;), of which you can see the top 20 in the following screenshot:

How to do it...

Examine the code of the command-line project processing_lines using the following methods:

  1. Using the readAsLines method as shown in the following code:

    import 'dart:io';
    // for step 3:
    import 'dart:async';
    import 'dart:convert';
    
    main() {
      File data= new File("../winequality-red.csv");
      data.readAsLines().then(processLines)
      .catchError((e) => handleError(e));
    }
    
    processLines(List<String> lines) {
      // process lines:
      for (var line in lines) {
      print(line);
      }
    }
    
    handleError(e) {
      print("An error...

Unlock full access

Continue reading for free

A Packt free trial gives you instant online access to our library of over 7000 practical eBooks and videos, constantly updated with the latest in tech
bookmark search playlist font-size

Change the font size

margin-width

Change margin width

day-mode

Change background colour

Close icon Search
Country selected

Close icon Your notes and bookmarks

Delete Bookmark

Modal Close icon
Are you sure you want to delete it?
Cancel
Yes, Delete