Java NIO2 – Files class part 3 In this section we continue with the Java NIO2 and Files class. Files.list This Java NIO2 method returns a stream of Path object only from the path (the elements of child folders not included in the return stream). Note that the method can throws an IOException. Say that…
Java NIO2 – Files class part 2 In this section we continue with the Java NIO2 and Files class. Files.move This method creates a test folder (package) inside the src folder. We will test moving the test.txt file from src folder to src/test folder: Run the code and we can see that the file test.txt…
Introduction to Java NIO2 and Files class Java NIO2 is about addition of much improved file and filesystem manipulation and addressing API. The package we need to import is java.nio.file Files class The java.nio.file.Files class is the main entry point of the java.nio.file package. It is different from the java.io.File class. Files class is a…
Java Test for Java NIO Don’t try to hack or to do something unusual, this is just some basic Java tests for Java NIO, to see what we learned until now. Please try to finish these tests without using an IDE. After choosing your options (radio buttons) please press Check button to see the result….
Uniform Resource Identifier URI is short for Uniform Resource Identifier, the URI begin with a schema that specifies resource type. The full path of URI class is java.net.URI, we can convert a Path object to URI with toUri() method as in the next example: Run the code and we have the output like this (depend…
Some useful methods of Path interface toString This method returns a string from the Path object: This will output: or in Windows: To output the absolute path, we have to call to first: This will output: Note that Java will automatically use \ for Windows and / for Linux/MacOs. We can use both of these…
Introduction to Java NIO The interfaces java.nio.file.Path in Java NIO is the replacement for the java.io.File class in Java IO. Both File or Path object may refer to the relative path or absolute path in the file system. Both can refer to a file or a folder, in fact, files and folders are stored in…
Java Test for Data Streams Don’t try to hack or to do something unusual, this is just some basic Java tests for Data Streams, to see what we learned until now. Please try to finish these tests without using an IDE. After choosing your options (radio buttons) please press Check button to see the result….
Data Streams In this example, we will learn about the Data Stream: DataOutputStream and DataInputStream. These are byte stream. And we also study more about buffer streams. In the previous example, we use character streams. And the source is a text file. But a binary file is different. We cannot read the binary file directly…
Introduction to Buffered Stream FileInputStream, FileOutputStream, FileReader, FileWriter are all low-level streams that connect directly to the sources, and they will read or write each time a byte (8-bit data) or a char (16-bit data). There are high-level streams that take these low-level streams as a parameter, and process the I/O better than we do…