Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
Streams, File I/O
and Scanner class
ANUBHAV CHATURVEDI
File Descriptors
an abstract indicator for accessing a file ( int )
The three standard descriptors in unistd.h:
Standard Input : STDIN_FILENO
Standard Output : STDOUT_FILENO
Standard Error : STDERR_FILENO
Standard Streams
Let’s make life simple
Adding Layers of abstraction
The java.io package
EchoConsole.java example
CopyFile.java example
ExchangeStreams.java example
Why two constructors and how are
they different?
There are two ways to initialize FileInputStream… why?
FileInputStream(String name)
and
FileInputStream(File file)
Internal implementation
public FileInputStream(String name) throws FileNotFoundException {
this(name != null ? new File(name) : null);
}
Why two different classes –
FileReader and FileInputStream?
Unicode Character Encoding
2 byte vs 1 byte transfer
Byte stream and character stream
The Readers and Writers are Character streams
All seems to be good so far
But there is one problem…
IT’S NOT SIMPLE ENOUGH
Adding another Layer of
abstraction
Scanner.java
java.util package
More complex and useful than other available classes
Abstraction level attained:
Read Files and Streams
Perform Regex operation
Checking and getting available data types contained in the string
ScannerReadingFile.java example
Reference
http://tutorials.jenkov.com/java-io/index.html