课程: Java: Advanced Concepts for High-Performance Development
今天就学习课程吧!
今天就开通帐号,24,700 门业界名师课程任您挑!
Creating a new file - Java教程
课程: Java: Advanced Concepts for High-Performance Development
Creating a new file
- [Instructor] A task that comes up fairly often in software development is the need to work with files in some way. So to begin with, let's look at how we can create a new empty file in Java. So in this example, I have a class called FileCreationExample with an empty main method inside it. So to create a new file, I'm going to use a class in the java.nio package called Path. So I'm going to add a new line inside my main method and I'm going to say Path path. Then I'm going to say equals. And then I'm going to use a class called Paths. So I'm going to say Paths and then I'm going to call a static method called get. And then I'm going to pass in the path to the file that I want to create. So I'm going to say that I want it to be inside source, main Java and I'll put it inside 0 7, 02, and I'll call it example.txt. Then I just need to make sure that I've imported the path class from java.nio.file. And I've also got…