Contents

stringWithContentsOfFile:usedEncoding:error:

Returns a string created by reading data from the file at a given path and returns by reference the encoding used to interpret the file.

Declaration

+ (instancetype) stringWithContentsOfFile:(NSString *) path usedEncoding:(NSStringEncoding *) enc error:(NSError **) 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.

  • error:

    If an error occurs, upon returns contains an NSError object that describes the problem. If you are not interested in possible errors, you may pass in NULL.

Return Value

A string created by reading data from the file named by path. If the file can’t be opened or there is an encoding error, returns nil.

Discussion

This method attempts to determine the encoding of the file at path.

See Also

Creating and Initializing a String from a File