From the course: Java 8 Essential Training
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Managing files with Java 7's new I/O library - Java Tutorial
From the course: Java 8 Essential Training
Managing files with Java 7's new I/O library
- In Java 7, a new IO library was introduced that greatly simplified a lot of common operations. You can only use this library in Java 7 and later and unfortunately, at least at this point, it has not been implemented for Android. So Android developers will still need to use those older classes. But I'll show you how to accomplish the same task I did earlier, copying a simple file. In this project, NewIO, I'm once again starting with the file named loremipsum.txt in a file subdirectory of the project. And this time, I'll be able to copy the file with far less code. I'll start in my Main method by creating two instances of a class named Path. The Path class is a member of the package java.nio.file and it needs to be imported. A Path object can point to either a directory or a file. In this case, it's going to point to my loremipsum.txt file. To get the reference to the file, I'll use another class named Paths. All of the methods of this class are static and I'll use this one, the get…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.