Home > Java > Javagetting Started > There are several forms of construction methods of File class in Java

There are several forms of construction methods of File class in Java

王林
Release: 2020-07-20 16:52:11
forward
3001 people have browsed it

There are several forms of construction methods of File class in Java

File objects represent files and directories that actually exist on the disk.

(Recommended tutorial: java introductory tutorial)

The File class has the following forms of construction methods:

1. Through the given parent Abstract pathname and subpathname strings create a new File instance.

File(File parent, String child);
Copy after login

2. Create a new File instance by converting the given pathname string into an abstract pathname.

File(String pathname)
Copy after login

3. Create a new File instance based on the parent pathname string and child pathname string.

File(String parent, String child)
Copy after login

4. Create a new File instance by converting the given file: URI into an abstract pathname.

File(URI uri)
Copy after login

(Video tutorial recommendation: java video tutorial)

Code implementation:

package com.dhb.file;
import java.io.File;
import java.io.IOException;
/**
 * @author DSHORE / 2018-6-22
 *
 */
public class Demo1 {
  public static void main(String[] args) throws IOException {
    File file = new File("F:/a.txt");//指定路径  [构造函数]
    file.createNewFile();//创建文件(空文件)  [方法]    
    File files = new File("F:\","b.txt");//第一个参数是路径,第二个参数是要创建文件的文件名  [构造函数]
    files.createNewFile();//创建文件(空文件)  [方法]
  }
}
Copy after login

The above is the detailed content of There are several forms of construction methods of File class in Java. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:csdn.net
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template