Files, File Reading, File Writing Flashcards
where do computers store files
secondary devices eg hard disk, flash drives, DVDs etc
what is a byte-based stream
when input and output is in binary format
how many bytes in a characer
2
how many bytes in an int
4
how many bytes in a double
8
what is character based stream
output and input is a sequence of characters
example of character based stream
ASCII
Unicode
when would binary storage be used
images, videos
example of byte based file extensions
.jpeg
.png
example of character based file extensions
.txt
3 java input/output streams directly attached to console
system. in
system. out
system. err
can system.err be redirected? why might you want this?
yes
eg send to manufactures so they can debug and fix the problem
void write (byte[] arr) method in javaFileOutput stream does what
writes arr.length bytes from the bytes array to the output stream
how to write specific amounts from byte array
void write(byte[] array, int offset, int length)
how to write an individual byte in the array
voif write(int b)
how to close the file
why
name.close();
nothing will we written until its closed
convert the string myString to a byte array
byte [ ] byteArray = myString.getBytes( );
what does the function getBytes( ) allow us to do
get the string as a sequence of bytes
getBytes is a fucntion within what class
fileOutput stream
what is java file input stream used for
read from a file
what does int read() method in the file input stream do
returns the number of bytes that were read from the input file
how to read up to b.length bytes of data from file input stream
iint read(byte [ ] b);
how to read a certain length of bytes from a file input stream
int read( byte [] b, int offset, int length)
how to know when file has finished being read
will return -1