createReader()

本参考资料用于Processing 3.0+。 如果你使用的是前一版本,请在使用软件帮助菜单内的参考资料。. If you see any errors or have suggestions, please let us know. If you prefer a more technical reference, visit the Processing Core Javadoc and Libraries Javadoc.

名称

createReader()

示例


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();


   }
  }  
描述 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.

语法
createReader(filename)
参数
filename String: name of the file to be opened
返回值 BufferedReader
相关 createWriter()

Updated on October 2, 2018 05:02:07pm EDT

createReader()