CORE API / CATATAN</>↗Core API08 Des 2012
In this example you’ll see how to copy a file using the new API provided in the JDK 7. The first step is to define the source and the target of the file to be copied. For this we can use the Path class. To create an instance of Path we use the Paths.get() method […]
CORE API / CATATAN</>↗Core API05 Des 2012
This code snippet show you how to split string with multiple white-space characters. To split the string this way we use the "\s+" regular expression. The white-space characters include space, tab, line-feed, carriage-return, new line, form-feed. Let’s see the code snippet below: package org.kodejava.lang; import java.util.Arrays; public class SplitStringMultiSpaces { public static void main(String[] args) […]
CORE API / CATATAN</>↗Core API05 Des 2012
In this example you’ll learn how to clear or reset the content of an array. We can use the java.util.Arrays.fill() method to replace to content of each element in the array. In the example below we create two arrays, names and numbers array. We initialize these arrays with some values and then clear the value […]
CORE API / CATATAN</>↗Core API05 Des 2012
This example show you how to validate input when using java.util.Scanner. To validate input the Scanner class provides some hasNextXXX() method that can be use to validate input. For example if we want to check whether the input is a valid integer we can use the hasNextInt() method. In the code snippet below will demonstrate […]
CORE API / CATATAN</>↗Core API04 Des 2012
This example show you how to use the DosFileAttributes class to get file attribute that support DOS file system. This class extends the BasicFileAttributes class. Using the DosFileAttributes class we can read file attributes using isArchive(), isHidden(), isReadOnly() and isSystem() methods. Let’s see the code snippet below: package org.kodejava.io; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; […]
CORE API / CATATAN</>↗Core API04 Des 2012
This code snippet show you an example on how to set the value of file attributes. Here we will set the DosFileAttributes. To set the value of file attributes we use the Files.setAttributes() method. To set DosFileAttributes we can use the following attributes: "dos:archive", "dos:hidden", "dos:readonly" and "dos:system". For details let’s see the code snippet […]