IO Flashcards
nacteni file.txt do input streamu
InputStream in = new FileInputStream(“file.txt”);
output stream to file.txt
OutputStream out = new FileOutputStream(“file.txt”);
FileInputStream - co umi
Umi cist z file do inputStream (v bytech)
InputStreamReader - co umi
prevest stream bytu na stream charu
BufferedReader - co umi
precist radek z charoveho streamu: br.readLine()
FileOutputStream - co umi
umi ze streamu bytu zapisovat do souboru
OutputStreamWriter
prevadi stream charu na stream bytu
BufferedWriter - co umi
umi zapisovat do charoveho streamu: bw.println(“x”)
Zapis radku “x” do souboru file.txt
try (BW out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(“file.txt”)))) {
out.println(“x”);
}
Vypis radku ze souboru file.txt na stdout
try (BR in = new BufferedReader(new InputStreamReader(new FileInputStream(“file.txt”)))) {
String line;
while (line = in.readLine() != null) {
sout(line);
}
}
Alternativa k new InputStreamReader(new FileInputStream(file))
new FileReader(file, charset)
Alternativa k new OutputStreamWriter(new FileOutputStream(file))
new FileWriter(file, charset)
Jake mame tridy pro zapis/cteni mezi streamy
PipedInput/OutputStream
PipedReader/Writer
Jake mame tridy pro zapis/cteni objektu do streamu
ObjectInput/OutputStream
vytvor charset pro UTF-8
Charset.forName(“UTF-8”)