Instance Method インスタンスメソッド

writeToFile:atomically:encoding:error:

Writes the contents of the receiver to a file at a given path using a given encoding. レシーバの内容をある与えられたパスでのファイルに、ある与えられた符号化を使って書き込みます。

Declaration 宣言

- (BOOL)writeToFile:(NSString *)path 
         atomically:(BOOL)useAuxiliaryFile 
           encoding:(NSStringEncoding)enc 
              error:(NSError * _Nullable *)error;

Parameters パラメータ

path

The file to which to write the receiver. If path contains a tilde (~) character, you must expand it with stringByExpandingTildeInPath before invoking this method. レシーバを書き込むファイル。pathがチルダ(~)文字を含むならば、あなたはそれをstringByExpandingTildeInPathで、このメソッドを発動する前に展開しなければなりません。

useAuxiliaryFile

If YES, the receiver is written to an auxiliary file, and then the auxiliary file is renamed to path. If NO, the receiver is written directly to path. The YES option guarantees that path, if it exists at all, won’t be corrupted even if the system should crash during writing. YESならば、レシーバは補助ファイルに書き出されます、それから補助ファイルはpathに改名されます。NOならば、レシーバは直接にpathへと書き出されます。YESオプションはpathを保証します、それがともかく存在するならば、システムが書き出しの間にクラッシュするとしても。

enc

The encoding to use for the output. For possible values, see NSStringEncoding. 出力のために使われる符号化。可能な値として、NSStringEncodingを見てください。

error

If there is an error, upon return contains an NSError object that describes the problem. If you are not interested in details of errors, you may pass in NULL. エラーがあるならば、戻りでは、問題を記述するNSErrorオブジェクトを含みます。あなたがエラーの詳細に興味がないならば、あなたはNULLを渡すかもしれません。

Return Value 戻り値

YES if the file is written successfully, otherwise NO (if there was a problem writing to the file or with the encoding). YES、もしそのファイルがうまく書き込まれるならば、そうでなければNO(ファイルへの書き込みまたは符号化で問題があった場合)。

Discussion 議論

This method overwrites any existing file at path. このメソッドは、pathでの何らかの既存のファイルを上書きします。

This method stores the specified encoding with the file in an extended attribute under the name com.apple.TextEncoding. The value contains the IANA name for the encoding and the CFStringEncoding value for the encoding, separated by a semicolon. The CFStringEncoding value is written as an ASCII string containing an unsigned 32-bit decimal integer and is not terminated by a null character. One or both of these values may be missing. Examples of the value written include the following: このメソッドは、指定された符号化をファイルに供給します、拡張された属性で、名前com.apple.TextEncodingのもとで。値は、符号化に対するIANA名と符号化に対するCFStringEncoding値を含みます、セミコロンで隔てられます。CFStringEncoding値は、符号なし32ビット10進整数を含んでいるASCII文字列として書き込まれます、そしてヌル文字で終端されません。これらの値の1つまたは両方は、欠けているかもしれません。書き出される値の例は以下を含みます:

  • MACINTOSH;0

  • UTF-8;134217984

  • UTF-8;

  • ;3071

The methods initWithContentsOfFile:usedEncoding:error:, initWithContentsOfURL:usedEncoding:error:, stringWithContentsOfFile:usedEncoding:error:, and stringWithContentsOfURL:usedEncoding:error: use this information to open the file using the right encoding. メソッドinitWithContentsOfFile:usedEncoding:error:initWithContentsOfURL:usedEncoding:error:stringWithContentsOfFile:usedEncoding:error:、そしてstringWithContentsOfURL:usedEncoding:error:は、この情報を使うことでファイルを正しい情報を使って開きます。

See Also 参照

Writing to a File or URL ファイルまたはURLに書き込む