Skip to content

Commit 945cb97

Browse files
author
tugul
committed
java.nio.file package supports system independent resources
1 parent ce860ab commit 945cb97

File tree

2 files changed

+14
-14
lines changed

2 files changed

+14
-14
lines changed

nio2/PathCreation.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,20 @@
1111
* - java.nio.file.Path
1212
* primary entry point of java.nio package
1313
* representation of path(file/directory) in a file system
14-
* Path is system dependent, can't compare path from DOS/Windows with one from Unix based systems
15-
*
16-
* Path object can be created various ways
14+
* system dependent, can't compare path from DOS/Win with one from POSIX/Unix based systems
1715
*
1816
*/
1917
public class PathCreation {
2018
public static void main(String[] args) throws URISyntaxException {
2119

20+
// Path object can be created various ways
21+
2222
// 1. Create Path using Paths helper class
2323
Path path1 = Paths.get("README.md");
2424
Path path2 = Paths.get("..", "nio2/README.md"); // constructing paths
2525

26-
System.out.println(path1.toAbsolutePath());
27-
System.out.println(path2.toAbsolutePath());
26+
System.out.println(path1.toAbsolutePath()); // /home/workspace/CoreJava/README.md
27+
System.out.println(path2.toAbsolutePath()); // /home/workspace/CoreJava/../nio2/README.md
2828

2929
// 2. Construct Path from URI resource
3030
Path path3 = Paths.get(new URI("file:/c:/user/google/docs")); // refer to URI based resource
@@ -38,7 +38,7 @@ public static void main(String[] args) throws URISyntaxException {
3838
//Path path5 = fileSystem.getPath("README.md");
3939

4040
// 5. Create path from File object. File to Path, and vice versa
41-
File file = new File("CoreJava/src/nio2/README.md");
41+
File file = new File("CoreJava/nio2/README.md");
4242
Path path6 = file.toPath();
4343
file = path6.toFile();
4444

nio2/README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1+
# NIO (Non-blocking IO)
12

2-
**Java.nio** package is initially started to replace java.io package(Non-blocking io), but hasn't taken off until second version of nio API in Java 7 which is called nio2.
3-
NIO2 actually intended to replace java.io.File class and its related interactions.
3+
``java.nio`` package is initially started to replace ``java.io`` package(Non-blocking io), however it hasn't taken off until the second version of nio API in Java 7 which is called **nio2**. **NIO2** actually intended to replace ``java.io.File`` class and its related interactions.
4+
5+
- ``java.nio.file.Path`` refers to resource on filesystem which doesn't have to exist. And most of its operations don't require it too.
6+
- ``java.nio.file.Paths`` is a factory/helper class for ``Path``
47

5-
Paths - factory/helper class for Path
6-
Path refers to resource on filesystem which doesn't have to exist. And most of its operations doesn't require too.
78

8-
NIO2 API has following advantages over IO API:
9+
**NIO2** API has following advantages over old **IO** API:
910
* supports file-system dependent attributes (DOS, POSIX)
10-
* allows you traverse directory hierarchy directly
11+
* allows you directly traverse directory hierarchy
1112
* supports symbolic link in file system
12-
* when reading multiple attributes of a file, it's faster
13-
13+
* faster when reading multiple attributes of a file
1414

1515

0 commit comments

Comments
 (0)