Java introduced the powerful Stream API to support functional-style operations. This tutorial will show how to find distinct elements of Stream by property or attribute. Find distinct elements natively Returns a stream consisting of...
When working with JAXB, sometimes you want a String representation of your XML. This tutorial will show how to JAXB marshal to String. Below the code of marshaling to String.
ClassWeWantToMarhsall cc = ...;
JAXBContext context = JAXBContext.newInstance(ClassWeWantToMarhsall.class);
Marshaller m = context.createMarshaller();
StringWriter sw = new StringWriter();
String result = sw.toString()
This tutorial shows 5 different ways to convert InputStream to String in Java.
Sometimes you need to delete files having certain extension within a directory. Two approach are possible, you can either list all files within the directory and check their extension before deletion or list only files having the extension using...
There is several ways to copy file from one location to another. 4 ways will be shown here : Writing a InputStream to an OutputStream Using FileChannel Using java.nio.file.Files Using Apache Commons IO FileUtils
There are several ways to append content to an existing file in Java. Below three ways to do it : Using FileWriter Using java.nio.file.Files Using Apache Commons IO FileUtils 1- Using FileWriter JDK 1.4+ Since...
In this article, we will see how to make a secured LDAP authentication using Java. First thing to do is importing the trust certificate to Java keystore. The default java keystore is named cacerts and...
If you try to delete a not empty folder, a java.nio.file.DirectoryNotEmptyException will be thrown. This tutorial will show 4 differents ways to delete folder recursively in Java : Native Java WalkFileTree Apache Commons IO SpringUtils...
Sometimes you need to have an idea about what happens on your JVM. In fact, your need to profile and monitor your Java Virtual Machine to see how your resources are used. Three ways...
Problem Sometimes you face the following error while runing an executable jar : No main manifest attribute, in “<APP_NAME>.jar” Solution Main-class property is missing on your jars META-INF/MANIFEST.MF. Correct it by adding the following...