java 2 3
fdsa
fdsa
-
- 1 / 496
-
Flashcards
How to rename a file/directory with a File-Object?
boolean renameTo(File dest)
What is the benefit of a BufferedOutput-Stream?
Can write a large chunk of bytes at a time, reducing round-tips and improve perfomance
Which two sets of stream-classes are difined in the java.io.API? How does the names end?
- Byte-streams that end in InputStream/OutputStream
- Character streams that end in Reader/Writer
Are Reader/Writers still streams?
Yes, I/O Streams
What are advantages of using a characterstream even if byte streams can do everything?
They are specificially focused on managing character/stringdata -> no need to worry about the underlying characterencoding of the file
Does the class PrintReader exist compliant to PrintWriter?
No
Is there a InputStream class for PrintStream?
Npo
What are the four abstract parents of all Streams?
InputStream, OutputStream, Reader, Writer
Whats wrong here?:
- new BufferedInputStream(new FileReader("z.txt"));
- new BufferedWriter(new FileOutpuitStream("z.txt"));
- new ObjectInputStream(new FileOutputStream("z.txt"));
- new BufferedInputStream(new InputStream());
- Mix reader/writer
- "
- Mix outputStream with InputStream
- InputStream is a abstract class
Whats the stream-class for reading file data as bytes? Low/Highlvl?
FileInputStream - low
Whats the stream-class for writing file data as bytes? Low/Highlvl?
FileOutputStream - low
Whats the stream-class for reading file data as characters? Low/Highlvl?
FileReader -low
Whats the stream-class for writing file data as characters? Low/Highlvl?
FileWriter - low
Whats the stream-class for reading byte data from exsting InputStream in buffered manner? Low/Highlvl?
BufferedInputStream - high
Whats the stream-class for writing byte data to an existing outputstream in a buffered manner? Low/Highlvl?
BufferedOutputStream - High
Whats the stream-class for reading character data from exsting Reader in a buffered manner? Low/Highlvl?
BufferedReader - high
Whats the stream-class for writing character data to an existing writer in a buffered manner? Low/Highlvl?
BufferedWriter
Whats the stream-class for deserializing primitive java datay types and graphs of java objects from an existing InputStream ? Low/Highlvl?
ObjectInputStream - High
Whats the stream-class for serializing primitive java data types and graphs of java objects to an existing outputstream? Low/Highlvl?
ObjectOutputStream - High
Whats the stream-class for writing formatted representations of java objects to a binary stream? Low/Highlvl?
PrintStream - High
Whats the stream-class for writing formatted representations of objects to a character stream? Low/Highlvl?
PrintWriter - High
Does OutputStream/Writer.write and IntputStream/Reader.read() use byte-values?
No, ints: void write(int b); int read()
Whats the signature of InputStream/reader.read?
public int read() throws IOException
Whats the Sginature of OutputStream/writer.write()?
public void write(int b) throws IOException
How to check if an InputStream is at the end?
will return -1
What does offset 5, length 3 mean for a OutputStream?
should read up to 3 bytes and put them into the array stating with position 5
Are there read/write methods for Output/Input-stream/Reader/writer with offset and length?
Yes, overloaded, f.e.:
read(byte[] b, int offset, int length)
write(char[] c, int offset, int length)
How to close a IOStream?
public void close() throws IOException
Where should a stream which is passed around be closed?
In the method that created it
How to check if a stream supports mark()?
public boolean markSupported()
What dopes the readlimit mean in mark?
Instructs the stream that we expect to call reset() after at most x-bytes. if later: it may throws an exception, depending on the stream class
What does the returnparam of skip tells us?
How many values actuell got skipped
Whats the signature for closing a stream and releasing resoruces ? For what stream class(es)?
void close() - All streams
Whats the signature for reading a single byte/return -1 if no bytes are availiable? For what stream class(es)?
int read() -- all input-streams
Whats the signature for reading values into a buffer, returning the number of bytes read? For what stream class(es)?
int read(byte[] b) / int read(char[] c) : InputStream / Reader
Whats the signature for reading up to length values into a buffer starging from offset, returning number of bytes read? For what stream class(es)?
- int read(byte[] b, int offset, int length) - InputStream
- int read(char[] c, int offset, int length) - Reader
Whats the signature for writing a single byte? For what stream class(es)?
void write(int) - all output streams
Whats the signature for writing an array of values into the stream? For what stream class(es)?
- void write(byte[] b) - OutputStream
- void write(char[] c) - Writer
Whats the signature for writing length values from an array into the stream, starting with an offset index? For what stream class(es)?
- void write(byte[] b, int offset, int length) - OutputStream
- void write(char[] c, int offset, int length) - Writer
Whats the signature for returning true if the stream supports mark? For what stream class(es)?
boolean markSupported() - All input streams