Read contents from console or command line (Scanner/ Java/ Example)

Scanner class is a text parser, which is used to parse primitives & strings using regular expression. Scanner split the input into token using delimiter pattern. Default delimiter pattern is a whitespace. We will read the contents from console or command line using Scanner class. Scanner class extends object & implements Closeable & Iterable interface. 1.… Read More »

Java Scanner example – read & write contents to/ from file (example)

Scanner is text parser which used to parse primitives & strings using regular expression. Scanner split the input into token using delimiter pattern. Default pattern delimiter is whitespace. We will write content to a file using FileWriter class. Then, we will read content from as file using Scanner class. Scanner class extends object & implements… Read More »

Inter thread communication in java (Example/ PipedInputStream / PipedOutputStream)

Inter thread communication is very common phenomenon. There are many ways to achieve inter thread communication. In current post, we will use pipes to achieve thread communication. Java has set of classes named PipedOutputStream & PipedInputStream to communicate between threads. We will create couple of threaders namely producer & consumer. Producer thread will produce data… Read More »

Create new file & folder (directory) in java (with example)

Given a path in java, create a new folder/directory & file using File class. File class has following methods to create file & directory in java. We will create directory in non existed path using mkdirs api. Also, we will create new directory & file using mkdir & createNewFile respectively. Program: create new file &… Read More »

Unzip or decompress files in java using ZipInputStream & ZipEntry (example)

Given a zipped or compressed file in java. Write a program to unzip or decompress the contents of zip file using ZipInputStream in java. Zip file may contain nested directory structure. e.g. Zip file may have compressed files having following directory structure. FirstFile.txt SecondFile.txt Dir1\Dir1_F1.txt Dir1\Dir1_F2.txt Dir1\Dir11\Dir11_F1.txt Dir1\Dir11\Dir11_F2.txt ….. Read the content of zip files… Read More »

Page 1 of 4112345...102030...Last »