CORE API / CATATAN</>↗Core API02 Apr 2013
To open a file for writing in JDK 7 you can use the Files.newBufferedWriter() method. This method takes three arguments. We need to pass the Path, the Charset and a varargs of OpenOption. For example, in the snippet below we pass the path of our log file, we use the StandardCharsets.UTF_8 charset, and we use […]
CORE API / CATATAN</>↗Core API02 Apr 2013
In the snippet below you’ll learn to open file for reading using Files.newBufferedReader() method in JDK 7. This method returns a java.io.BufferedReader which makes a backward compatibility with the old I/O system in Java. To read a file you’ll need to provide a Path and the Charset to the newBufferedReader() method arguments. package org.kodejava.io; import […]
CORE API / CATATAN</>↗Core API30 Mar 2013
In the following code snippet you will learn how to move a file using the java.nio.file.Files helper class of JDK 7. This class simplify how you can move file. To move file you need to define the Path of the source and the target file. We use the Files.move() method to move the file by […]
CORE API / CATATAN</>↗Core API25 Mar 2013
In this example we are going to learn to use the DirectoryStream, which part of java.nio.file package, to find files in a directory. We begin by creating a Path, the directory where the search will be conducted. After that we create a DirectoryStream using Files.newDirectoryStream(). To create a directory stream we passed two arguments, the […]
CORE API / CATATAN</>↗Core API24 Mar 2013
In this example you’ll learn how to create and delete a file. Using the new Files class helper from the JDK 7 you can create a file using the Files.createFile(Path) method. To delete a file you can use the Files.delete(Path) method. Before create a file and delete a file we can check to see if […]
CORE API / CATATAN</>↗Core API23 Mar 2013
In this example you’ll learn how to use the Files.walkFileTree() to walk through file tree. This method requires two parameters. The first parameter is the starting file, in this example we’ll start from drive F:/Temp. And the second parameter is the file visitor to invoke for each file. Here we’ll create a file visitor call […]