Java I/O processing

Source: Internet
Author: User

Tag: INF exists in text sources file read/write Res path property

The file class contains the properties for obtaining a file/directory, as well as a method for renaming and deleting files/directories.

The file class contains many methods for getting file properties, as well as methods for renaming and deleting files and directories, but the file class does not contain methods to read and write the contents of files

The file object encapsulates the properties of the files or paths, but he does not include the method of creating the file or the method of reading/writing the data from/to the file.

File input and output

Write Data using PrintWriter

The PrintWriter class can be used to create a file and write data to a text file.

You can create a PrintWriter object first, and then call the print, println, and printf methods to write data to the file

The usual methods are as follows:

Example:

You must use the close () method if it is not used, the data is not saved correctly in the file.

Using try-with-resources to automatically close resources

Java I/O processing

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.