Reading a file as a String in Dart
It took me a minute to work out how to read a file in Dart (vm), so here it is for posterity:
Notes:
void main() { File f = new File('my_filename.txt'); FileInputStream fileStream = f.openInputStream(); StringInputStream stringStream = new StringInputStream(fileStream); print(stringStream.read()); fileStream.close(); }
Notes:
- A StringInputStream reads strings from an InputStream
- A FileInputStream is an implementor of InputStream that is opened from files
- Remember to close the FileInputStream