Compress or zip files using ZipOutputStream in java (example)

Given the input files, we would like to zip or compress input files. Java framework has provided couple of classes to create a zip. ZipOutputStream: ZipOutputStream class implements an output stream filter for writing files in the ZIP file format. ZipEntry: ZipEntry class represents a ZIP file entry. e.g. If we want to zip file named… Read More »

Write or redirect standard output error stream to a file in java

We write error of an application(s) to standard error stream using System.err.print*. System.err.println(“1. Write error to a file”); We would like to redirect the application errors to a file.  e.g. System.err.println(“1. Write error to a file”) should be written to a file. We would like to set output stream, so that all errors will be… Read More »

Convert String to Integer in java (with example)

Given an String in java, we would like convert String to integer. We can convert String to integer using following methods. Convert String to integer using Integer.parseInt. Convert String to integer using Integer.valueOf. Convert String to integer using Integer constructor. Program – convert String to Integer in java (with example) package org.learn; public class ConvertStringToInt { public… Read More »

List all files (excluding directories) recursively in java

Given an input directory of file system. We would like to list files only i.e. we do not want to list directories. We will recursively traverse all sub directories to list files. Program – list all files (excluding directories) recursively in java package org.learn; import java.io.File; public class ListFilesOnly { private static int serialNumber = 0; public… Read More »

List all directories of input path using scope operator & file filter in java

Given an input directory of a file system. We would like to list or print all directories recursively. We will traverse all directories and sub directories to list directories (only). We will discuss couple of options to list directories (refer trailing code). We will scope resolution operator to filter directories  Method name: listDirectoriesUsingScope. We will… Read More »

Page 3 of 4112345...102030...Last »