FileInputStream example

xiaoxiao2021-03-31  215

// Demonstrate FileInputStreamimport java.io *;. Class FileInputStreamDemo {public static void main (String [] args) throws Exception {int intSize; InputStream f = new FileInputStream ( "FileInputStreamDemo.java"); System.out.println ( "Total Available Bytes: " (INTSIZE = F.available ()));

INT N = INTSIZE / 40; System.out.Println ("First" N "bytes of the file one read () at a time."); for (int i = 0; i

Byte b [] = new byte [n]; if (f.Read (b)! = n) {system.out.println ("COULDN't Read" n "bytes.");} system.out. Println (New String (B, 0, N)); System.out.Println ("/ Nstill Available:" (INTSIZE = F.available ())); System.out.Println ("Skipping Half of Remaining Bytes with Skip () "); f.skip (INTSIZE / 2); System.out.println (" STILL AVAILABLE: " F.available ()); System.out.Println (" Reading " N / 2 " INTO "); if (F.Read (B, N / 2, N / 2)! = n / 2) {system.out.println (" COULDN '' @ n / 2 "bytes ");} System.out.println (new string (b, 0, b.length); system.out.println (" / nstill available: " f.available ()); f.close (); }

转载请注明原文地址:https://www.9cbs.com/read-130903.html

New Post(0)