Home » Core Java » io » File (page 2)

File

Construct a File Path in Java example

In this example we will see how to create a File Path in Java. The idea is very simple. You want your program to be able to create a File and store it in a particular File Path in your system. Let’s say that your program wants to create and store a file in your Home directory. The problem is ...

Read More »

PipedReader PipedWriter example

In this example we shall show you how to use the PipedReader and the PipedWriter. The PipedReader is a class for reading piped character-input streams, whereas the PipedWriter is a class for writing to piped character-output streams. To use the PipedReader and the PipedWriter we have performed the following steps: We have created a thread, MyThread that extends the Thread. ...

Read More »

Tokenize a java source file

With this example we are going to demonstrate how to tokenize a java source file. In short, to tokenize a java source file you should: Create a new FileReader. Create a new StreamTokenizer that parses the given FileReader. Use parseNumbers() API method of StreamTokenizer that specifies that numbers should be parsed by this tokenizer. Use wordChars(int low, int hi) API ...

Read More »

Count words and numbers in a file

This is an example of how to count the words and numbers in a File. Counting the words and numbers in a File implies that you should: Create a new FileReader. Create a new StreamTokenizer that parses the given FileReader. Keep an int word counter and a number word counter. Iterate over the tokens of the tokenizer. For every token, ...

Read More »

Set eolIsSignificant example

In this example we shall show you how to use the eolIsSignificant(boolean flag) method of a StreamTokenizer to determine whether or not ends of line are treated as tokens. To use eolIsSignificant(boolean flag) method one should perform the following steps: Create a new FileReader. Create a new BufferedReader using the fileReader. Create a new StreamTokenizer that parses the given bufferedReader. ...

Read More »

Set whitespaceChars example

With this example we are going to demonstrate how to use the whitespaceChars(int low, int hi) method of a StreamTokenizer. This method specifies that all characters c in the range low <= c <= high are white space characters. In short, to use the whitespaceChars(int low, int hi) method you should: Create a new FileReader. Create a new BufferedReader using ...

Read More »

Read a file using StreamTokenizer

This is an example of how to read a File using the StreamTokenizer. The StreamTokenizer class takes an input stream and parses it into “tokens”, allowing the tokens to be read one at a time. Reading a File using the StreamTokenizer implies that you should: Create a new FileReader. Create a new StreamTokenizer that parses the given fileReader. Iterate over ...

Read More »

Growable array of ints example

In this example we shall show you how to create a growable array of ints. We have created an example of how to create serializable objects and how to store them in Files and then retrive them and create copies of the objects. We have performed the following steps: SerialIntList implements the Serializable. It has two protected properties, an int ...

Read More »

StringReader example

With this example we are going to demonstrate how to use a StringReader. The StringReader is a character stream whose source is a string. In short, to use a StringReader you should: Create a new StringReader with a specified String. Create a new StreamTokenizer using the reader. Iterate over the tokens of the tokenizer, and for every token if it ...

Read More »

Decompress a zip folder

With this example we are going to demonstrate how to decompress a zip folder in Java. In short, to decompress a zip folder you should: Create a FileInputStream by opening a connection to an actual file, the file named by the path name name in the file system. Create a new ZipInputStream. Iterate over the ZipEntries of the ZipInputStream, using ...

Read More »