IO Flashcards

1
Q

nacteni file.txt do input streamu

A

InputStream in = new FileInputStream(“file.txt”);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

output stream to file.txt

A

OutputStream out = new FileOutputStream(“file.txt”);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

FileInputStream - co umi

A

Umi cist z file do inputStream (v bytech)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

InputStreamReader - co umi

A

prevest stream bytu na stream charu

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

BufferedReader - co umi

A

precist radek z charoveho streamu: br.readLine()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

FileOutputStream - co umi

A

umi ze streamu bytu zapisovat do souboru

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

OutputStreamWriter

A

prevadi stream charu na stream bytu

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

BufferedWriter - co umi

A

umi zapisovat do charoveho streamu: bw.println(“x”)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Zapis radku “x” do souboru file.txt

A

try (BW out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(“file.txt”)))) {
out.println(“x”);
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Vypis radku ze souboru file.txt na stdout

A

try (BR in = new BufferedReader(new InputStreamReader(new FileInputStream(“file.txt”)))) {
String line;
while (line = in.readLine() != null) {
sout(line);
}
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Alternativa k new InputStreamReader(new FileInputStream(file))

A

new FileReader(file, charset)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Alternativa k new OutputStreamWriter(new FileOutputStream(file))

A

new FileWriter(file, charset)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Jake mame tridy pro zapis/cteni mezi streamy

A

PipedInput/OutputStream
PipedReader/Writer

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Jake mame tridy pro zapis/cteni objektu do streamu

A

ObjectInput/OutputStream

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

vytvor charset pro UTF-8

A

Charset.forName(“UTF-8”)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Nacteni vsech radku ze souboru file.txt do seznamu

A

Files.readAllLines(Path.of(“file.txt”));

17
Q

Jak se nactou byty z readeru do bufferu? (2)

A

read(buffer)
read(buffer, offset, length) - kolik se preskoci a kolik vezme
vraci pocet nactenych bytu (nebo -1)

18
Q

Jak se oznaci pozice ve streamu?

A

is.mark(5)

19
Q

Jak se input stream prevede na output stream

A

is.transferTo(os)

20
Q

Output writer - jak se zapise z bufferu (byte[]) do streamu

A

os.write(buffer, offset, length) - offset je u bufferu

21
Q

Co dela flush na streamu?

A

Zapise na vystup a smaze frontu

22
Q

Metody zmeny pozice v binarnim streamu (2)

A

is.skip(5)
is.reset()

23
Q

Jak zjistim zbyvajici pocet bytu ve streamu?

A

is.available()

24
Q

Checky: input stream - lze oznacovat pozici?
textovy input stream - lze cist?

A

is.markSupported()
is.ready()

25
Q

Soubor file.txt - zapis do souboru file2.txt (binarne)

A

try (InputStream is = new FileInputStream(“file.txt”);
OutputStream os = new FileOutputStream(“file2.txt”)) {
byte[] bytes = new byte[1024];
while ((length = is.read(bytes)) != -1) {
os.write(bytes, 0, length);
}
}

26
Q

Trida pro cteni bytu ze souboru do streamu

A

FileInputStream

27
Q

Trida pro prevod input streamu s byty na input stream se znaky

A

InputStreamReader

28
Q

Trida pro cteni ze znakoveho input streamu po radcich

A

BufferedReader

29
Q

Trida pro zapis streamu bytu do souboru

A

FileOutputStream

30
Q

Trida pro prevod output streamu charu na output stream bytu

A

OutputStreamWriter

31
Q

Trida pro zapis do znakoveho output streamu po radcich

A

PrintWriter

32
Q

InputStream pro stdin, PrintWritery pro stdout, a stderr

A

System.out, System.in, System.err

33
Q

Jak se cte ze stdin? dokud tam neni hodnota exit

A

Scanner s = new Scanner(System.in);
String txt;
while ((txt = s.nextLine()) != “exit”) {
sout(txt);
}

34
Q

Jak zapisu do konzole “str”?

A

System.console().writer().println(“str”);

35
Q

Jak prectu z konzole radek?
Co vraci, kdyz dosly radky?

A

String line = System.console().reader().readLine()
null