?????????????
?????????????????????????????????????????顣
???????Runnnable??????
????void startAThread0(){
????new Thread(new MyRunnable()).start();
????}
????class MyRunnable implements Runnable{
????public void run(){
????...
????}
????}
???????Thread??????
????void startAThread1(){
????new MyThread().start();
????}
????class MyThread extends Thread{
????public void run(){
????...
????}
????}
???????????Thread??????
????void startAThread2(){
????new Thread(){
????public void run(){
????...
????}
????}.start();
????}
?????????????run()?????????????Thread.start()?????????????????????μ?????????????????run()??
?????ο???java.lang.Thread??java.lang.Runnable??
???????try-finally
????I/O???????
????void writeStuff()throws IOException{
????OutputStream out=new FileOutputStream(...);
????try{
????out.write(...);
????}finally{
????out.close();
????}
????}
???????????
????void doWithLock(Lock lock){
????lock.acquire();
????try{
????...
????}finally{
????lock.release();
????}
????}
???????try???????????????????????????finally???鯔????С??????????????????????????????????????
???????try??????????????????????????????л?????finally????????о????????????????????????????????????????????????Χ??finally???飩??
???????????????????????
????InputStream in=(...);
????try{
????while(true){
????int b=in.read();
????if(b==-1)
????break;
????(...process b...)
????}
????}finally{
????in.close();
????}
????read()??????????????δ????????????????0??255??????0??255?????????????????????-1??
?????ο???java.io.InputStream.read()??
??????????????????????
????InputStream in=(...);
????try{
????byte[]buf=new byte[100];
????while(true){
????int n=in.read(buf);
????if(n==-1)
????break;
????(...process buf with offset=0 and length=n...)
????}
????}finally{
????in.close();
????}
?????????????read()???????????????????buf????????????????????п???????????
?????ο???java.io.InputStream.read(byte[])??java.io.InputStream.read(byte[]??int??int)??
????????????????
????BufferedReader in=new BufferedReader(
????new InputStreamReader(new FileInputStream(...)??"UTF-8"));
????try{
????while(true){
????String line=in.readLine();
????if(line==null)
????break;
????(...process line...)
????}
????}finally{
????in.close();
????}
????BufferedReader??????????ú?????????????Java?????????????????????????????????????C??????????
?????????????κ??????InputStream??????FileInputStream??????socket??
??????????????????BufferedReader.readLine()????null??
???????ζ?????????????Reader.read()??????
???????????????????????????????UTF-8?????ò??????????
?????ο???java.io.BufferedReader??java.io.InputStreamReader??