FileHandle
クラスにはfileHandleWithStandardOutput
メソッドがあります。ドキュメントによると、「従来、これはプログラムからデータのストリームを受信する端末デバイスです。」
私がやりたいのは、128バイトごとにファイルを読み取り、fileHandleWithStandardOutput
メソッドを使用して端末に表示することです。
これは、128バイトごとにどのように読み取っているのかを示すコードフラグメントです。
i = 0;
while((i + kBufSize) <= sourceFileSize){
[inFile seekToFileOffset: i];
buffer = [inFile readDataOfLength: kBufSize];
[outFile seekToEndOfFile];
[outFile writeData: buffer];
i += kBufSize + 1;
}
//Get the remaining bytes...
[inFile seekToFileOffset: i ];
buffer = [inFile readDataOfLength: ([[attr objectForKey: NSFileSize]intValue] - i)];
[outFile seekToEndOfFile];
[outFile writeData: buffer];
kBufSizeは、128に等しいプリプロセッサです。
私の答え:
outFileをfileHandleWithStandardOutput
..の戻りNSFileHandleに設定します。
以前に試しましたが、うまくいきませんでした。そして今はうまくいきました。他に何かがあるか、何かが干渉している可能性があります。とにかく私は今答えを得ました。