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

initWithContentsOfFile:usedEncoding:error:

Returns an NSString object initialized by reading data from the file at a given path and returns by reference the encoding used to interpret the characters. NSStringオブジェクトを返します、データをある与えられたパスでのファイルから読み出すことによって初期化されます、そして参照によって文字を解釈するのに使った符号化を返します。

Declaration 宣言

- (instancetype)initWithContentsOfFile:(NSString *)path 
                          usedEncoding:(NSStringEncoding *)enc 
                                 error:(NSError * _Nullable *)error;

Parameters パラメータ

path

A path to a file. ファイルへのパス。

enc

Upon return, if the file is read successfully, contains the encoding used to interpret the file at path. For possible values, see NSStringEncoding. 戻りでは、ファイルがうまく読み出されたならば、pathでのファイルを解釈するのに使われた符号化を含みます。可能な値として、NSStringEncodingを見てください。

error

If an error occurs, upon returns contains an NSError object that describes the problem. If you are not interested in possible errors, pass in NULL. エラーが発生するならば、戻りでは問題を記述するNSErrorオブジェクトを含みます。あなたが起こりうるエラーに興味がないならば、NULLを渡してください。

Return Value 戻り値

An NSString object initialized by reading data from the file named by path. The returned object may be different from the original receiver. If the file can’t be opened or there is an encoding error, returns nil. あるNSStringオブジェクトで、pathによって指名されるファイルからデータを読み出すことによって初期化されます。返されるオブジェクトは、元のレシーバと異なるかもしれません。ファイルが開かれることができないまたは符号化エラーがあるならば、nilを返します。

Discussion 議論

See Also 参照

Creating and Initializing a String from a File 文字列をファイルから作成して初期化する