Java_File Operations

There are five classes and one interface in the java.io package:

File operation class: File

Stream operation classes: InputStream, OutputStream, Reader, Writer

An interface: Serializable

 

Through the File class, operations such as creating and deleting directory lists can be performed on files, which have nothing to do with the operation content.

Set the operation completion path: puiblic File(String pathname) Enterprise development use

Set parent path and child file: public File(File parent,String child) Android use

 

Field operation method:

  Create a new file: createNewFile()

import java.io.File;

public class Hello{
    public static void main(String[] args) throws Exception {
        File file = new File( " F:\\Test.txt " ); // Two \\ represent one \ 
        file.createNewFile();
    }
}

Determine whether the path exists: exists()

Delete path: delete()

 

Determine whether it is a directory: isDirectory()

Determine whether it is a file: isFile()

Get file size: length()

Get the last modified date: lastModified()

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324486419&siteId=291194637