21 (1) byte stream

Byte stream

Writing data (in bytes transmitted) ---- ----- FileOutputStream file output stream of bytes to txt file

Txt file automatically after conversion when you bit special byte is written to an output file when txt, txt file will receive these bytes into characters, the characters when you read txt file as input, the txt file then converted into the output character byte

    // the path name to create a byte output stream
         // will detect if there is no path exists to create a new file, if there will be coverage
         // to true is to allow additional representatives, not to write is the default is false cover 
        FileOutputStream os = new new a FileOutputStream ( "D: \\ C.txt", to true );
         // write the data stream is not byte --- most buffer 
        os.write ( "in" .getBytes ()); // Get byte array
         // off flow 
        os.close ();

Acquiring data from a txt file (in bytes transmitted) ------ ----- the FileInputStream file input stream of bytes

// byte input stream object 
        the FileInputStream IS = new new the FileInputStream ( "D: \\ 3.txt" );
         // read the data byte to the end flag is -1 transformed into the corresponding character
         // System.out.println ( is.read ()); // 3.txt 456 is stored in the output is 52
         // self buffers 
        byte [] = BS new new  byte [10 ];
         int len = -1 ;
         the while ((len = iS .read (bs)) = -. 1) {! // returns the number of bytes written bs or -1 
            System.out.println ( new new String (bs, 0 , len)); 
        } 
        // off flow 
        is .close (); 
    }

 

Guess you like

Origin www.cnblogs.com/xuwangqi/p/11233956.html