0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

ProcessingでCSVファイルの読み込み・書き込み

Posted at

CSVファイルのデータを加工するツールとして、Excel や Google のスプレッドシートが挙げられますが、
加工するデータが膨大だったり、複雑な加工をしたいときは Processing が便利です。

読み込み

InputSample.pde
void setup(){
  // CSVファイルを読み込み、行ごとにStringとして受け取る
  String[] lines = loadStrings("InputFileName.csv");
}

書き込み

OutputSample.pde
void setup(){
  // 書き込み先となるCSVファイルを作成する
  PrintWriter outputFile = createWriter("OutputFileName.csv");

  // CSVファイルに書き込む(実際には出力する値を貯める、バッファに追加される)
  outputFile.println( "ABC,DEF,GHI" );

  // 書き込みを実行する(バッファに貯まった値をファイルに出力する)
  file.flush();

  // ファイル操作を終了する
  file.close();
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?