java learning exception handling and file streams.
A Exception handling: 1. To avoid problems: determining whether there is an index
用if判断 ArrayList list=new ArrayList();
if(0<list.size()){
System.out.println(list.get(0));}
2. The method of abnormality appears to solve the problem: Capture Society exception statement, try {statement} is error-prone "trial" means, the catch (encapsulated into objects, and passed to the parameter) as "capture."
There can be multiple catch statements.
try{
ArrayList list=new ArrayList();
System.out.println(list.get(0)):
}catch(IndexOutOfBoundsException e){
e.printStackTrace ();
}
java inside all the exception classes packaged in a Exception class, all exception classes inherit from Exception.
Finally, there is a selective finally statement added according to the needs, regardless of the code is an exception, finally statement executes.
Second file stream:
File:
Text files, non-text files (binaries)
Folder (directory)
The file from the hard disk to the memory interface: read, read, the input, the Input, the input stream
Saving data from memory to the hard disk inside: a memory write, an output, the Output output stream
File f = new File (String pathName); full catalog
File f = new File (String parent, String child); parent directory plus subdirectories
File f = new File (File parent, String child); parent directory plus child
Java learning next week, and looked like the test volume.