How to Use File Separator to construct file path in java?

How to Use File Separator to construct file path in java?

Many java developers might have came across the code where the developer need to use file separator for the file path or directory path. Many of them are using “/” or “\” depending upon the operating system. Using the forward or backward slash is not a good practice while coding in the java, because your code may …

Read More

How to get current working directory in java?

How to get current working directory in java?

You can get current working directory using System.getProperty(“user.dir”) function. Here current working directory means the root folder of your current Java project. Below java code shows how to get current working directory of user –   References: Oracle Java Docs for System Properties

Read More

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 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