Some conclusions about IO streams

IO streams: the flow of data I -> intput inflow O -> output effluent    

  java, jvm byte between the hard disk and the flow into and out of a reference jvm is, is hard to flow into the jvm, jvm outflows to the hard disk

  There are four top-level IO streams [abstract] parent

  InputStream input stream of bytes the bytes output InputStream

  Character-input stream output stream Reader Writer character [only] for text manipulation

  The associated implementation class will construct a file, if the associated output stream, if the file does not exist can not be created automatically generated. If the associated input stream, if the file does not exist can not find the file will be reported abnormal

  The basic method used writer read flush with [automatically refreshed in the character stream for the output file entry associated with the characters stored into the buffer, (not a byte stream, direct deposit bytes) Use the close call this method [ ]

  Some functions and features of the implementation class

  Buffer flow; Buffer ******: four elementary streams [File ****] enhancement. It can add an buffer. The elementary stream read / write to the byte buffer memory, without frequent jvm elementary stream to flow between the hard disk. The read and write efficiency

  Commutations: Bridge encoding and decoding functions byte characters. You can specify the encoding system [Chinese present reading windows (gbk encoding is used by default), garbled (compiled software typically utf-8)] [not avoid distortion, encoding the reader consistent]

  Sequence / deserialization stream: a load / store instances of objects stored in the hard disk of the text object must implement Serializable not want to be stored in the member variable modified by transient   

          Consistent write-read version of the sequence [format: static final long serialVersionUID = 42L]

  Print streams: unpaired, only the output stream

          PrintSteam PrintWriter characteristics and differences

            Features the same point: with their own unique way print / println format can be output to any type of | only output

            Differences: when they turn on the automatic line feed structure       PrintStream as long as the line break will refresh      PrintWriter will only be automatically refreshed when println / printf / famart method call

  Memory Operation Flow:   not associated with any file, reading or writing data in memory, without closing ByteArrayInputStream ByteArrayOutputStream

 Data input and output streams: basic data types can be read write type sequence {} DataInputStream DataOutputStream require a consistent
 Random access stream: there is a breakpoint to download the file pointer []
          Construction: RandomAccessFile (File file, String mode) mode file type rw: read-write
          method
             in.seek (0); set file pointer position boolean b = raf.readBoolean (); obtaining position of the pointer file [string when entering, will be more than two bytes ready for starting entry string]
 SequenceInputStream: represents the logical series of other input streams. It, and read from the input stream is an ordered collection started from the first input stream, until the end of the file, then reads the input stream from the second, and so on, until the end of the last contains a file input stream until
             SequenceInputStream(InputStream s1, InputStream s2)


 

  proterties    stored key-value pair [dual column set, Hashtable subclass, are key character / string [key] into connection with the equal sign, because reading is divided according to the equal sign [] is automatically stored overtime data]    

               [Stored key pair is read, is not] # comments

 

          Specific methods: the setProperty (String Key, String value) Add pair String getProperty (String key) corresponding to the key value obtained Set <String> stringPropertyNames () key set obtained

 

                load () to read the key store () output key parentheses (afferent input and output streams related to the input and output files, annotations)

 

 

                public void store (OutputStream out, String comments) (Writer writer, String comments) byte stream using Chinese distortion []   

                Note You can not use the Chinese [windows (default gbk coding)] [default compiler software for general use unicode] [empty string]

 

Other Tidbits

Scanner(InputStream source)         构造一个新的 Scanner,它生成的值是从指定的输入流扫描的。
PrintStream out = System.out; 关联屏幕 out标准”输出流。此流已打开并准备接受输出数据。通常,此流对应于显示器
InputStream in = System.in;//in 关联的是键盘“标准”输入流。此流已打开并准备提供输入数据。通常,此流对应于键盘输入
键盘录入的第二种方式
Scanner scanner = new Scanner(System.in);
从文件扫描
Scanner scanner = new Scanner(new FileInputStream("a.txt"));

解耦思想:分离整体——————>将整体数据的分为部分1和部分2,可以新建一个3,将整体数据的部分2和部分3的对应起来。通过原整体之间部分2与部分1,变为3来对应部分1
ArrayList<Object> list2 = new ArrayList<>();————————>添加数据
   Random random = new Random();
int i = random.nextInt(list2.size());---------------->生成一个随机索引
System.out.println(list2.get(i));-------------------->解耦:程序和数据解耦

  

 

 

String s="wdwa";
Byte[] bytes=str.getBytes(); [B@1b6d3586
new String(bytes) wdwa
Arrays.toString(bytes) [119, 100, 119, 97]
String s1 = String.valueOf(chars, 0, len);----->不能转换byte类型和其他类型数组【char类型除外】

 

 

 

 

Guess you like

Origin www.cnblogs.com/arroa/p/11879452.html