by Dinesh Thakur Category: Stream

The FileOutputStream class is used for creating or writing into the file. For more advanced file output, we use the RandomAccessFile class. A FileOutputStream object can be created using one of the following constructors:

 
by Dinesh Thakur Category: Stream

In Split Function Java Example, the string t is split into pieces (wherever space has occurred in it) with the help of split() method and all its pieces are then stored in the string array h. Then, the length of the string h is computed by length() function and the loop is invoked in reverse to display the tokens stored in string array h in reverse order.

 
by Dinesh Thakur Category: Stream

Properties is a subclass of Hashtable. It uses a list of values in which key and value is a String. many other Java classes  use Properties.

 
by Dinesh Thakur Category: Stream

java.util.StringTokenizer class split String into different token by “space” and “comma” delimiter.



 
by Dinesh Thakur Category: Stream

The StringTokenizer class is used to create a parser for String objects. It parses strings according to a set of delimiter characters. It implements the Enumeration interface in order to provide access to the tokens contained within a string. StringTokenizer provides three constructors:

 
by Dinesh Thakur Category: Stream

The Hashtable class implements a hash table data structure. A hash table indexes and stores objects in a dictionary using hash codes as the objects keys. Hash codes are integer values that identify objects. All different objects are assigned different hash values and therefore different dictionary keys.

 
by Dinesh Thakur Category: Stream

The BitSet class is used to create objects that maintain a set of bits. The bits are maintained as a growable set. The capacity of the bit set is increased as needed. Bit sets are used to maintain a list of flags that indicate the state of each element of a set of conditions. Flags are boolean values that are used to represent the state of an object. It is used for representing a set of true and false values.

 
by Dinesh Thakur Category: Stream

The Stack class provides the capability to create and use stacks within the Java programs. Stacks are· storage objects that store information by pushing it onto a stack and remove and retrieve information by popping it off the stack. Stacks implement a last-in-first-out storage capability: The last object pushed on a stack is the first object that can be retrieved from the stack. The Stack class extends the Vector class.



 
by Dinesh Thakur Category: Stream

The SequencelnputStream class allows you to concatenate (or combine) two or more input streams serially and make them appear as if they were a single input stream. Each input stream is read beginning from the first one until end of file (EOF) is reached, where upon it reads from the second one and so on, until end of file is reached on the last of the contained input streams.

 
by Dinesh Thakur Category: Stream

The java.io.PrintWriter is another very convenient I/O class that makes writing text to a file as easy as writing text to the console. The PrintWri ter class defines several constructors, the one we would be using is as follows.



 
by Dinesh Thakur Category: Stream

The java.io.BufferedReader and java.io.BufferedWriter classes are the character based equivalents of the byte oriented BufferedlnputStream and BufferedOutputStream classes.



 
by Dinesh Thakur Category: Stream

Java provides java.io.FileReader and java.io.FileWriter classes for reading from and writing characters to a file. The FileReader and FileWri ter classes can be used almost identically to the FileInputStream and FileOutputStream character stream classes.



 
by Dinesh Thakur Category: Stream

Java also allows you to access the contents of a file in random order i.e. data items can be read and written in any order. This is especially useful in direct access applications such as banking systems, airline reservation systems, Automatic Teller Machine (ATM) etc. where the desired information must be located immediately. Random access files (or direct access files) are analogous to arrays, where each element is accessed directly by means of its index number. Java provides java.io.RandomAccessFile class that enables you to perform random access file input and output operations as opposed to sequential file I/O offered by ByteStream and CharacterStream classes.



 
by Dinesh Thakur Category: Stream

Java also supports writing and reading objects to stream (such as a file). The process of reading and writing objects in a file is called object serialization. Writing an object to a file is called serializing the object and reading the object back from a file is called deserializing an object. In Java, serialization occurs automatically. Objects can be converted into a sequence of bytes, or serialized, by using the java.io.ObjectOutputStream class and they can be deserialized or converted from bytes into a structured object, by using java.io.ObjectlnputStream class.



 
by Dinesh Thakur Category: Stream

The BufferedOutputStream class is a subclass of FilterOutputStream that stores written data in an internal buffer (a protected byte array field named buf) until the buffer is full or the stream is explicitly flushed using the flush ()method. Then it writes the data onto the underlying output stream all at once. This class does not declare any new methods of its own, rather all the methods are inherited from the OutputStream class.

 
by Dinesh Thakur Category: Stream

When you need to process primitive types, Java provides DatalnputStream and DataOutputStream classes.

The DatalnputStream class is a subclass of FilterlnputStream that reads bytes from a stream and converts them into appropriate primitive type values or strings.

 
by Dinesh Thakur Category: Stream

In this Java Example in the main () method of the class FileIOStream, an instance fileOutput of FileOutputStream is created to write to the file mydata.dat. Then using the for loop, we write the square of the value stored in the index variable i using the write () method to the file mydata.dat. The output stream is then closed by calling the close () method.

 
by Dinesh Thakur Category: Stream

In order in create File object, the File class provides the following constructors.

• File (String pathname): Creates a File object associated with the file or directory specified by pathname. The pathname can contain path information as well as a file or directory name.



 
by Dinesh Thakur Category: Stream

File is a predefined class present in java.io package. listFiles method is a predefined method of File class.

This method is used to show the list of files present in the specified directory.
Syntax- public File[] listFiles()



 

Page 2 of 3



About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.SC (Computer Science), MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.



Related Articles