课程: Java for All Platforms: Desktop, Web, and Mobile Development

今天就学习课程吧!

今天就开通帐号,24,700 门业界名师课程任您挑!

Read data from a file

Read data from a file

- [Instructor] Another important feature of a programming language is the ability to read data from a file. So let's take a look at how that works with Java. So I'm going to create a folder for external assets and by that I mean assets we can load into our code that don't go inside of our packages. Like this one right here. And we can do that by right clicking our project and choosing New, Directory. I'll call this assets. And then I'm going to right click assets and choose New, File. We'll call this example.txt. And then write some text in here on multiple lines. Just like that. Save the file and head back to your code. In the code, we're going to load this using the file class. So create an instance of the file class, which is in the java.io package. And then we'll call this file with a lowercase f and we'll set it equal to a new File, passing in the path of the file. The path is relative to the root of our…

内容