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.