I/O (1) Mars notes in Java --- (compilation exceptions occur when I/O programs are compiled, so we need to try... Exception in cath processing)

Source: Internet
Author: User

Io operation target

Io Flow

Core classes in Io

Core Methods

Int Len is length

Import Java. io. *; public class test {public static void main (string ARGs []) {// declare that the input stream references fileinputstream fiis = NULL; try {// generate the object that represents the input stream. The object is the new fileinputstream ("E:/Baidu player/a.txt "); // generate a byte array byte [] buffer = new byte [100]; // call the read method of the input stream object to read data. read (buffer, 0, buffer. length); For (INT I = 0; I <buffer. length; I ++) {system. out. println (buffer [I]);} catch (exception e) {system. out. println (e );}}}

Output result:

The 96 results output later are all 0. They overwrite the previous 0 results.

Why is ABCD 97 99 100? Because ABCD
The ASCII code is 97 98 99 100.

Public class test {public static void main (string ARGs []) {// declare the input stream to reference read fileinputstream's fiis = NULL; try {// generate the object that represents the input stream. The object is the new fileinputstream ("E:/Baidu player/a.txt "); // generate a byte array byte [] buffer = new byte [100]; // call the read method of the input stream object to read data. read (buffer, 5, buffer. length-5); For (INT I = 0; I <buffer. length; I ++) {system. out. println (buffer [I]);} catch (exception e) {system. out. println (e );}}}

Output

After 5th zeros, 97 98 99 100 101, why is the first five 0, because the offset offeset offset is 5

Why is ABCD 97, 98, 99, 100, 101? Because the abcd ascii Code corresponds to 97 98 99 100 101

The third case is to remove the remaining amount.

For (INT I = 0; I <buffer. length; I ++) {string S = new string (buffer); // call the trim method of a string object, the space at the beginning and end of the character string // and the blank character // "ABC Def" >>> "ABC Def" (the space in the middle is retained) S = S. trim (); system. out. println (s );}

Import Java. io. *; public class test {public static void main (string ARGs []) {// declare the input stream reference to read fileinputstream's fiis = NULL; // declare the reference of the output stream to write fileoutputstream Fos = NULL; try {// generate the object that represents the input stream. The object is "New fileinputstream (" E:/Baidu player/a.txt "); // survival indicates the output stream object Fos = new fileoutputstream ("E:/Baidu player/write.txt "); // generate a byte array byte [] buffer = new byte [100]; // call the read method of the input stream object to read the data int temp = FCM. read (buffer, 0, buffer. length); FOS. write (buffer, 0, temp);} catch (exception e) {system. out. println (e );}}}

Output: The write.txt file is generated in this folder. A.txt is ABCDE, and write is ABCDE of a.txt .. The written content is copied successfully.

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.