Система ввода/вывода в Java package java. io. *; package java. nio. *; Dmitry Yablokov
java. io. File • • • • . list(); . list(Filename. Filer); . mkdirs(); . rename. To(); . delete. On. Exit(); . exists(); . can. Execute(); . can. Read(); . can. Write(); . is. Directory(); . length(); . last. Modified(); java. io. Filename. Filter • boolean accept(File dir, String name);
What are Streams ? ? ? byte Input. Stream byte Код Output. Stream • • • Файл Данные в памяти Экран Сетевое соединение Интернет соединение
Input. Stream Output. Stream File В час жаркого весеннего заката на Патриарших прудах появилось двое граждан. Первый из них — приблизительно сорокалетний, одетый в серенькую летнюю пару, — был маленького роста, темноволос, упитан, лыс, свою приличную шляпу пирожком нес в руке, а аккуратно…
I/O System classes Read Byte • Input. Stream • File. Input. Stream • Byte. Array. Input. Stream • Piped. Input. Stream • Sequence. Input. Stream Write Char Byte • Reader • Input. Stream. Reader • String. Reader • Char. Array. Reader • Piped. Reader • File. Reader • Output. Stream • File. Output. Stream • Byte. Array. Output. Stream • Piped. Output. Stream Char • Writer • Ouput. Stream. Writer • String. Writer • Char. Array. Writer • Piped. Writer • File. Writer Decorators • Filter. Input. Stream • Buffered. Input. Stream • Data. Input. Stream • Line. Number. Input. Stream • Stream. Tokenizer • Pushback. Input. Stream • String. Buffer. Input. Stream • Filter. Reader • Buffered. Reader • Line. Number. Reader • Stream. Tokenizer (Reader) • Pushback. Reader • Filter. Output. Stream • Buffered. Output. Stream • Data. Output. Stream • Print. Stream Random. Access. File • Filter. Writer • Buffered. Writer • Print. Writer
public class Filter. Input. Stream extends Input. Stream { /** * The input stream to be filtered. */ protected volatile Input. Stream in; /** * Creates a Filter. Input. Stream
* by assigning the argument in
* to the field this. in
so as * to remember it for later use. * * @param in the underlying input stream, or null
if * this instance is to be created without an underlying stream. */ protected Filter. Input. Stream(Input. Stream in) { this. in = in; }
public class Filter. Output. Stream extends Output. Stream { /** * The underlying output stream to be filtered. */ protected Output. Stream out; /** * Creates an output stream filter built on top of the specified * underlying output stream. * * @param out the underlying output stream to be assigned to * the field this. out for later use, or * null
if this instance is to be * created without an underlying stream. */ protected Filter. Output. Stream(Output. Stream out) { this. out = out; }
Reader Input. Stream. Reader String. Reader Char. Aray. Reader Bridge from byte stream to char one . mark(); . reset(); Piped. Reader . mark(); . reset(); File. Reader Decorators Filter. Reader Buffered. Reader Pushback. Reader . mark(); . reset(); . read. Line(); . unread(); Line. Number. Reader. get. Line. Number(); . set. Line. Number(); Other Stream. Tokenizer Не реализует interface Reader. next. Token(); sval; nval; ttype;
Writer Output. Stream. Writer String. Writer Char. Array. Writer Piped. Writer Bridge from byte stream to char one File. Writer Decorators Filter. Writer Buffered. Writer Print. Writer . new. Line(); . check. Error(); . new. Line(); . print(…); . println(…);
New Input/Output
import java. io. *; import java. net. URL; import java. nio. channels. File. Channel; private void copy. File(File incoming. File, File outgoing. File) throws IOException { File. Input. Stream fis = new File. Input. Stream(incoming. File); File. Output. Stream fos = new File. Output. Stream(outgoing. File); File. Channel in = fis. get. Channel(); File. Channel out = fos. get. Channel(); } in. transfer. To(0, in. size(), out);