Documentation

This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

matlab.io.datastore.DsFileReader class

Package: matlab.io.datastore

File-reader object for files in a datastore

Description

The DsFileReader object enables low-level file reading access for files in your datastore.

Construction

fr = matlab.io.datastore.DsFileReader(filename) returns a DsFileReader object for read access to the file specified by filename.

fr = matlab.io.datastore.DsFileReader(filename,'TextEncoding',encoding) specifies the character encoding scheme associated with the file. Additionally, specifying encoding sets the TextEncoding property of the DsFileReader object.

Input Arguments

expand all

File name, including the file extension, specified as a character vector or a string scalar. If the file is not in the current folder, filename must include a full or a relative path.

The Name property of the DsFileReader object stores the file name.

Example: 'myFile.txt'

Data Types: char | string

Character encoding scheme associated with the file, specified as the name of a standard, character-encoding scheme listed in this table.

'Big5'

'ISO-8859-1'

'windows-847'

'Big5-HKSCS'

'ISO-8859-2'

'windows-949'

'CP949'

'ISO-8859-3'

'windows-1250'

'EUC-KR'

'ISO-8859-4'

'windows-1251'

'EUC-JP'

'ISO-8859-5'

'windows-1252'

'EUC-TW'

'ISO-8859-6'

'windows-1253'

'GB18030'

'ISO-8859-7'

'windows-1254'

'GB2312'

'ISO-8859-8'

'windows-1255'

'GBK'

'ISO-8859-9'

'windows-1256'

'IBM866'

'ISO-8859-11'

'windows-1257'

'KOI8-R'

'ISO-8859-13'

'windows-1258'

'KOI8-U'

'ISO-8859-15'

'US-ASCII'

 

'Macintosh'

'UTF-8'

 

'Shift_JIS'

 

The TextEncoding property of the DsFileReader object stores the value specified in encoding.

Example: 'Shift_JIS'

Data Types: char | string

Properties

expand all

File name, specified as a character vector or string scalar.

Example: fr.Name returns the file name.

Data Types: char | string

File size in bytes, returned as a numeric scalar integer.

Example: fr.Size

Data Types: double

Character encoding scheme associated with the file, specified as the name of a standard, character-encoding scheme. To set the value for the TextEncoding property, see the description of the encoding input argument.

Example: 'TextEncoding','Shift_JIS'

Position pointer location in the file, specified as an integer. The position pointer is a zero-based integer that tracks the number of bytes from the beginning of the file.

If a file has n bytes of data, then those n bytes are in positions 0 through n-1.

You can set the Position property using the seek method. Calls to the read method begin reading the file from the location indicated by the Position property. When reading a file iteratively, the read method automatically updates the position pointer. Subsequent calls to the read method begin reading from the end position of the previous read operation.

Data Types: double

Methods

matlab.io.datastore.DsFileReader.hasdata Determine if data is available to read
matlab.io.datastore.DsFileReader.read Read bytes from file
matlab.io.datastore.DsFileReader.seek Seek to a position in the file

Examples

Read File Portion Specified by Starting Position and Size

Create a file-reader object for a file, seek to the desired starting position, and read a portion of the file.

Create a DsFileReader object for airlinesmall.csv.

fr = matlab.io.datastore.DsFileReader('airlinesmall.csv');

The airlinesmall.csv file has variable names at the beginning of the file. The variable names line ends at the position marked by 299 bytes. To get past the variable names line, use the seek method to move the read pointer to the starting position.

seek(fr,299,'RespectTextEncoding',true);

Read the first 1000 characters.

 if hasdata(fr)
    d = read(fr,1000,'SizeMethod','OutputSize','OutputType','char');
 end

Introduced in R2017b

Was this topic helpful?