www.javacup.ir sadegh aliakbary. copyright ©2014 javacup.irjavacup.ir all rights reserved....
TRANSCRIPT
Contents redistribution is allowed if JAVACUP is noted as the source
2
Copyright ©2014 JAVACUP.IRAll rights reserved. Redistribution of JAVACUP contents is not
prohibited if JAVACUP is clearly noted as the source in the used case.
JAVACUP shall not be liable for any errors in the content, or for any actions taken in reliance thereon.
Please send your feedback to [email protected]
JAVACUP.ir
Contents redistribution is allowed if JAVACUP is noted as the source
3
AgendaJava New APIs for IONIONIO.2
JAVACUP.ir
Contents redistribution is allowed if JAVACUP is noted as the source
4
The First Version of Java I/O APIsjava.io packageThe File class limitations:
more significant functionality required (e.g. copy method)
defines many methods that return a Boolean value In case of an error, an exception is better than a
simple false.Poor support for handling symbolic linksinefficient way of handling directories and pathsvery limited set of file attributes
JAVACUP.ir
Contents redistribution is allowed if JAVACUP is noted as the source
5
Java New IO (NIO)Introduced in Java 1.4 (2002)The key features of NIO were:Channels and SelectorsBuffersCharset
java.nio.charsetencoders, and decoders to map bytes and
Unicode symbols
JAVACUP.ir
Contents redistribution is allowed if JAVACUP is noted as the source
6
NIO.2Introduced in Java 1.7 (2011)Java 7 introduces the java.nio.file packageNew interfaces and classes
Path, Paths, and Files
JAVACUP.ir
Contents redistribution is allowed if JAVACUP is noted as the source
7
Path and PathsPath is an interface while Paths is a class
JAVACUP.ir
Contents redistribution is allowed if JAVACUP is noted as the source
8
Path interface
The toPath() method in the java.io.File class returns the Path object; this method was added
in Java 7The toFile() method in the Path interface to
get a File object
JAVACUP.ir
Contents redistribution is allowed if JAVACUP is noted as the source
9
The Files Classthe java.nio.file packageProvides static methods for copy, move,
delete, …New methods for
Symbolic linked filesAttributes…
JAVACUP.ir
Contents redistribution is allowed if JAVACUP is noted as the source
10
copyPath pathSource = Paths.get(str1);Path pathDestination = Paths.get(str2);Files.copy(pathSource, pathDestination);
it will not copy the files/directories contained in the source directory
you need to explicitly copy them to the destination folder
JAVACUP.ir
Contents redistribution is allowed if JAVACUP is noted as the source
11
Listening for ChangesPath path = Paths.get("..\\src");WatchService watchService = null;
watchService = path.getFileSystem().newWatchService();path.register(watchService, StandardWatchEventKinds.ENTRY_MODIFY);
JAVACUP.ir
Contents redistribution is allowed if JAVACUP is noted as the source
12JAVACUP.ir