當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Processing BufferedReader用法及代碼示例

Processing, 類BufferedReader用法介紹。

說明

BufferedReader 對象用於將文件 line-by-line 作為單獨的 String 對象讀取。



從處理版本 0134 開始,處理 API 加載和保存的所有文件都使用 UTF-8 編碼。在以前的版本中,使用了您平台的默認編碼,這在將文件移動到其他平台時會導致問題。

例子

BufferedReader reader;
String line;
 
void setup() {
  // Open the file from the createWriter() example
  reader = createReader("positions.txt");    
}
 
void draw() {
  try {
    line = reader.readLine();
  } catch (IOException e) {
    e.printStackTrace();
    line = null;
  }
  if (line == null) {
    // Stop reading because of an error or file is empty
    noLoop();  
  } else {
    String[] pieces = split(line, TAB);
    int x = int(pieces[0]);
    int y = int(pieces[1]);
    point(x, y);
  }
} 

方法

相關用法


注:本文由純淨天空篩選整理自processing.org大神的英文原創作品 BufferedReader。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。