GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Processing
  • Download
  • Reference
  • Environment
  • Libraries
  • Tools
  • Wiki
  • Tutorials
  • Examples
  • Books
  • Forum
  • Overview
  • People
  • Privacy

This view

  • Original page
  • New address

GeezerVison is showing processing.org — createReader() / Reference

Reference+
Documentation→Reference→Input→Files

Name

createReader()

Description

Creates a BufferedReader object that can be used to read files line-by-line as individual String objects. This is the complement to the createWriter() function. For more information about the BufferedReader class and its methods like readLine() and close used in the above example, please consult a Java reference.

Starting with Processing release 0134, all files loaded and saved by the Processing API use UTF-8 encoding. In previous releases, the default encoding for your platform was used, which causes problems when files are moved to other platforms.

Examples

  • void setup() {
      size(100, 100);
      parseFile();
    }
    
    void parseFile() {
      // Open the file from the createWriter() example
      BufferedReader reader = createReader("positions.txt");
      String line = null;
      try {
        while ((line = reader.readLine()) != null) {
          String[] pieces = split(line, TAB);
          int x = int(pieces[0]);
          int y = int(pieces[1]);
          point(x, y);
        }
        reader.close();
      } catch (IOException e) {
        e.printStackTrace();
      }
    } 
    

Syntax

  • createReader(filename)

Parameters

  • filename(String)name of the file to be opened

Return

  • BufferedReader

Related

  • createWriter()
Creative Commons License

This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.