70 likes | 200 Vues
This guide provides an overview of Java's input and output stream classes, detailing their functionalities such as reading, writing, and tokenizing data. Learn how to efficiently handle files using InputStreams, OutputStreams, and the StreamTokenizer. Explore key methods like `read()`, `write()`, and `close()`, and understand their exceptions. The tutorial highlights essential concepts such as the end-of-file marker and token types, making it easier for beginners to grasp file operations in Java.
E N D
Stream Classes Object InputStream OutputStream RandomAccess File Reader Writer StreamTokenizer FileInputStream FileOutputStream InputStreamReader OutputStreamReader FileReader FileWriter Streams of bytes Streams of Characters
Java’s View of a File of n bytes E O F n-1 0 2 ………………………………
InputStream/Reader public abstract int read() throws IOException Reads the next byte and returns its value (betweeen 0 and 255); returns –1 at the end. public void close() throws IOException Closes the input stream public void int available () throws IOException Returns the number of bytes that can be read from the input (Works only in InputStream)
OutputStream/Writer public abstract void write(int b) throws IOException Writes a byte (for OutputStream) or a character (for Writer) public void close () throws IOException Closes the output stream
StreamTokenizer Constant Description TT_WORD The token is a word. TT_NUMBER The token is a number. TT_EOL The end of the line has been read. TT_EOF The end of the file has been read. Variable Description int ttype Current token type double nval value of current token, if number String sval String that contains the characters of current token.