Java Step1: Basic knowledge 3

Source: Internet
Author: User

In 1.java, I/O is implemented using classes and interfaces in the Java.io package. File is one of the most commonly used classes in the Java.io package, which represents a file name (or directory name). Although the file class provides methods to work with directories and files within the corresponding directory, there is no way to work with the file contents. That is, it does not provide any way to read or write the bytes or characters contained in the file.

In 2.java, sequential file I/O is done through flow abstraction (random Access file I/O is done with the Randomaccessfile class, but sequential I/O is more common).

3. Assign a value to the args parameter of the main () function in eclipse:

Select Project Main class right-click the run configuration in run as

Select the 2nd tab (x) =arguments

Enter the parameters in program arguments, click Apply, and then click Run

For example my command exercise is:. +java

  

If you have multiple parameters, you can separate multiple parameters with a space.

Example 1: A short program that implements deleting a file or directory specified on the command line

4.FileInputStream reads the bytes of the source file and uses FileOutputStream to copy the bytes to the destination file.

Example 2 The Finally statement in the program ensures that the stream is properly closed before the program exits.

The stream reads and writes to the console: reading a line of text using BufferedReader, BufferedReader reads a single character from a InputStreamReader, and InputStreamReader from System.in ( This is a inputstream) read bytes, system.in will read the keystrokes on the user's keyboard. In addition, the program uses System.out and system.err to display text output, System.out and System.err are instances of PrintStream.

Example 2:

Java Step1: Basic knowledge 3

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.