How to write Exception’s PrintStackTrace to a File in Java?

How to write Exception’s PrintStackTrace to a File in Java?

Usually when you generate an exception in a Java program, you just print the exception to standard output using below code statement System.out.println(“Got an Exception: ” + e.getMessage()); But this is not what you want. Sometime you want to write Exception’s PrintStackTrace to a file and below Java program shows you how to write Exception’s …

Read More

How to convert Array to List in java?

How to convert Array to List in java?

Below code example show how to convert an array to List in java. To convert array based data into list, we can use java.util.Arrays class. This class provide a static method asList(Object[] a) that converts array into list. OUTPUT: TOM JACK JILL JANE

Read More

How to convert an array into a collection object?

How to convert an array into a collection object?

Below java code example show how to convert an array into a Collection object. To convert array based data into list / collection, we can use java.util.Arrays class. This class provide a static method asList(Object[] a) that converts array into list / collection. OUTPUT: TOM JACK JILL JANE

Read More

How to remove line or lines from a file in java?

How to remove line or lines from a file in java?

Below java code shows how to remove line from file /**************************************************************************************** * Created on 10-2011Copyright(c) http://kodehelp.com All Rights Reserved. ****************************************************************************************/ package com.kodehelp.javaio; import java.io.*; /** * Created by http://kodehelp.com * Date: 10/3/11 */ public class RemoveALine { public static void main(String args[]){ try { File inputFile = new File(“/conf.ini”); if (!inputFile.isFile()) { System.out.println(“Parameter is not …

Read More

How to get list of files using FileFilter class in java?

How to get list of files using FileFilter class in java?

Below java code shows how to get list of files using FileFilter class. FileFilter is an abstract class used by JFileChooser for filtering the set of files shown to the user. A FileFilter can be set on a JFileChooser to keep unwanted files from appearing in the directory listing.   Reference: Java Docs

Read More

Java Code Example for Hello World Program

Every beginner who starts programming in any language writes Hello World Program. Java Programmer is not exception for Hello World program. Below is the java version of Hello World Program. To start with Hello World java program you need to create HelloWorld.java file, Once you created file write class HelloWorld. The name of class and …

Read More