Java file directory read write delete operation detailed implementation code

I Get the information entered by the console user

It can return the information entered by the user. The disadvantage is that it does not support Chinese input and needs to be further improved.

II Copy file

1. Copy files by file stream

This method has been tested, supports Chinese processing, and can copy many types, such as TXT, XML, JPG, DOC and other formats

III Write file

1. Use printstream to write files

2. Use StringBuffer to write files

This method can set what kind of coding to use to effectively solve the Chinese problem.

IV File rename

V Transfer file directory

Transferring a file directory is not the same as copying a file. Copying a file means that the file exists in both directories after copying, while transferring a file directory means that the file exists only in the new directory after transferring.

Vi read file

1. Use FileInputStream to read files

2. BufferedReader and bufferedwriter will be more efficient in IO operation

3. Use Dom4j to read XML files

VII Create files (folders)

1. Create a folder

2. Create a new file

VIII Delete file (directory)

1. Delete file

2. Delete directory

When using the delete () method of file class to delete a directory, we must ensure that there are no files or subdirectories under the directory, otherwise the deletion fails. Therefore, in practical application, if we want to delete a directory, we must use recursion to delete all subdirectories and files under the directory, and then delete the directory.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>