No. | Function | Description |
1 | fopen() | opens new or existing file |
2 | fprintf() | write data into the file |
3 | fscanf() | reads data from the file |
4 | fputc() | writes a character into the file |
5 | fgetc() | reads a character from file |
6 | fclose() | closes the file |
7 | fseek() | sets the file pointer to given position |
8 | fputw() | writes an integer to file |
9 | fgetw() | reads an integer from file |
10 | ftell() | returns current position |
11 | rewind() | sets the file pointer to the beginning of the file |
Mode | Description |
r | opens a text file in read mode |
w | opens a text file in write mode |
a | opens a text file in append mode |
r+ | opens a text file in read and write mode |
w+ | opens a text file in read and write mode |
a+ | opens a text file in read and write mode |
rb | opens a binary file in read mode |
wb | opens a binary file in write mode |
ab | opens a binary file in append mode |
rb+ | opens a binary file in read and write mode |
wb+ | opens a binary file in read and write mode |
ab+ | opens a binary file in read and write mode |
Data Type | Description |
fstream | It is used to create files, write information to files, and read information from files. |
ifstream | It is used to read information from files. |
ofstream | It is used to create files and write information to the files. |
Welcome to javaTpoint.
C++ Tutorial.Output:Welcome to javaTpoint.C++ Tutorial.3. Read and Write ExampleLet's see the simple example of writing the data to a text file testout.txt and then reading the data from the file using C++ FileStream programming.
InputStream | OutputStream |
FIleInputStream | FileOutputStream |
ByteArrayInputStream | ByteArrayOutputStream |
ObjectInputStream | ObjectOutputStream |
PipedInputStream | PipedOutputStream |
FilteredInputStream | FilteredOutputStream |
BufferedInputStream | BufferedOutputStream |
DataInputStream | DataOutputStream |
Reader | Writer |
BufferedReader | BufferedWriter |
CharacterArrayReader | CharacterArrayWriter |
StringReader | StringWriter |
FileReader | FileWriter |
InputStreamReader | InputStreamWriter |
FileReader | FileWriter |
Sr.No. | Method & Description |
1 | public void close() throws IOException{} This method closes the file output stream. Releases any system resources associated with the file. Throws an IOException. |
2 | protected void finalize()throws IOException {} This method cleans up the connection to the file. Ensures that the close method of this file output stream is called when there are no more references to this stream. Throws an IOException. |
3 | public int read(int r)throws IOException{} This method reads the specified byte of data from the InputStream. Returns an int. Returns the next byte of data and -1 will be returned if it's the end of the file. |
4 | public int read(byte[] r) throws IOException{} This method reads r.length bytes from the input stream into an array. Returns the total number of bytes read. If it is the end of the file, -1 will be returned. |
5 | public int available() throws IOException{} Gives the number of bytes that can be read from this file input stream. Returns an int. |
Sr.No. | Method & Description |
1 | public void close() throws IOException{} This method closes the file output stream. Releases any system resources associated with the file. Throws an IOException. |
2 | protected void finalize()throws IOException {} This method cleans up the connection to the file. Ensures that the close method of this file output stream is called when there are no more references to this stream. Throws an IOException. |
3 | public void write(int w)throws IOException{} This methods writes the specified byte to the output stream. |
4 | public void write(byte[] w) Writes w.length bytes from the mentioned byte array to the OutputStream. |
Modifier | Type | Field | Description |
Static | String | pathSeparator | It is system-dependent path-separator character, represented as a string for convenience. |
Static | Char | pathSeparatorChar | It is system-dependent path-separator character. |
Static | String | separator | It is system-dependent default name-separator character, represented as a string for convenience. |
Static | Char | separatorChar | It is system-dependent default name-separator character. |
Constructor | Description |
File(File parent, String child) | It creates a new File instance from a parent abstract pathname and a child pathname string. |
File(String pathname) | It creates a new File instance by converting the given pathname string into an abstract pathname. |
File(String parent, String child) | It creates a new File instance from a parent pathname string and a child pathname string. |
File(URI uri) | It creates a new File instance by converting the given file: URI into an abstract pathname. |
Modifier and Type | Method | Description |
static File | createTempFile(String prefix, String suffix) | It creates an empty file in the default temporary-file directory, using the given prefix and suffix to generate its name. |
Boolean | createNewFile() | It atomically creates a new, empty file named by this abstract pathname if and only if a file with this name does not yet exist. |
Boolean | canWrite() | It tests whether the application can modify the file denoted by this abstract pathname.String[] |
Boolean | canExecute() | It tests whether the application can execute the file denoted by this abstract pathname. |
Boolean | canRead() | It tests whether the application can read the file denoted by this abstract pathname. |
Boolean | isAbsolute() | It tests whether this abstract pathname is absolute. |
Boolean | isDirectory() | It tests whether the file denoted by this abstract pathname is a directory. |
boolean | isFile() | It tests whether the file denoted by this abstract pathname is a normal file. |
String | getName() | It returns the name of the file or directory denoted by this abstract pathname. |
String | getParent() | It returns the pathname string of this abstract pathname's parent, or null if this pathname does not name a parent directory. |
Path | toPath() | It returns a java.nio.file.Path object constructed from the this abstract path. |
URI | toURI() | It constructs a file: URI that represents this abstract pathname. |
File[] | listFiles() | It returns an array of abstract pathnames denoting the files in the directory denoted by this abstract pathname |
Long | getFreeSpace() | It returns the number of unallocated bytes in the partition named by this abstract path name. |
String[] | list(FilenameFilter filter) | It returns an array of strings naming the files and directories in the directory denoted by this abstract pathname that satisfy the specified filter. |
Boolean | mkdir() | It creates the directory named by this abstract pathname. |
Sr.No. | Interface & Description |
1 | CharConversionException This is a base class for character conversion exceptions. |
2 | EOFException These are signals that an end of file or end of stream has been reached unexpectedly during input. |
3 | FileNotFoundException These are the signals that an attempt to open the file denoted by a specified pathname has failed. |
4 | InterruptedIOException This is signals that an I/O operation has been interrupted. |
5 | InvalidClassException This is thrown when the Serialization runtime detects one of the following problems with a Class. |
6 | InvalidObjectException This indicates that one or more deserialized objects failed validation tests. |
7 | IOException These are the signals that an I/O exception of some sort has occurred. |
8 | NotActiveException This is thrown when serialization or deserialization is not active. |
9 | NotSerializableException This is thrown when an instance is required to have a Serializable interface. |
10 | ObjectStreamException This is a superclass of all exceptions specific to Object Stream classes. |
11 | OptionalDataException This is an exception indicating the failure of an object read operation due to unread primitive data, or the end of data belonging to a serialized object in the stream. |
12 | StreamCorruptedException This is thrown when control information that was read from an object stream violates internal consistency checks. |
13 | SyncFailedException These are the signals that a sync operation has failed. |
14 | UnsupportedEncodingException This character encoding is not supported. |
15 | UTFDataFormatException This are signals that a malformed string in modified UTF-8 format has been read in a data input stream or by any class that implements the data input interface. |
16 | WriteAbortedException This are signals that one of the ObjectStreamExceptions was thrown during a write operation. |
Primitive Data Type | Default Value 3.6 |
byte | 0 |
short | 0 |
int | 0 |
long | 0L |
float | 0.0f |
double | 0.0d |
char | '\u0000' |
boolean | false |
Primitive Type | Size | Minimum Value | Maximum Value | Wrapper Type |
char | 16-bit | Unicode 0 | Unicode 216-1 | Character |
byte | 8-bit | -128 | +127 | Byte |
short | 16-bit | -215 | +215-1 | Short |
int | 32-bit | -231 | +231-1 | Integer |
long | 64-bit | -263 | +263-1 | Long |
float | 32-bit | Approx range 1.4e-045 to 3.4e+038 | Float | |
double | 64-bit | Approx range 4.9e-324 to 1.8e+308 | Double | |
boolean | 1-bit | true or false | Boolean |