1.用思惟導圖對javaIO操做的學習內容進行總結。java
2.下面的程序實現了文件的拷貝,但採用的是一個字節一個字節的讀寫方式,效率很低。使用緩衝區能夠減小對文件的操做次數,從而提升讀寫數據的效率。IO包中提供了兩個帶緩衝的字節流BufferedInputStream和BufferedOutputStream,查閱JDK幫助文檔,修改程序,利用這兩個類完成文件拷貝,對比執行效率。git
import java.io.*; public class Test{ public static void main(String args[]) { FileInputStream in=null; FileOutputStream out=null; File fSource=new File("d:"+File.separator+"my.jpg"); File fDest=new File("d:"+File.separator+"java"+File.separator+"my.jpg"); if(!fSource.exists()){ System.out.println("源文件不存在"); System.exit(1); } if(!fDest.getParentFile().exists()){ fDest.getParentFile().mkdirs(); } try { in=new FileInputStream(fSource); out=new FileOutputStream(fDest); int len=0; long begintime = System.currentTimeMillis(); while((len=in.read())!=-1){ out.write(len); } long endtime = System.currentTimeMillis(); System.out.println("文件拷貝完成,耗時"+(endtime-begintime)+"毫秒"); }catch(Exception e){ System.out.println("文件操做失敗"); }finally{ try { in.close(); out.close(); } catch (IOException e) { e.printStackTrace(); } } } }
用BufferedInputStream和BufferedOutputStream方法正則表達式
import java.io.*; public class Test{ public static void main(String args[]) { BufferedInputStream in=null; BufferedOutputStream out=null; try { BufferedInputStream fSource =new BufferedInputStream(new FileInputStream("d:"+File.separator+"my.jpg")); BufferedOutputStream fDest=new BufferedOutputStream(new FileOutputStream("d:"+File.separator+"java"+File.separator+"my.jpg")); in=new BufferedInputStream(fSource); out=new BufferedOutputStream(fDest); int len=0; long begintime = System.currentTimeMillis(); while((len=in.read())!=-1){ out.write(len); } long endtime = System.currentTimeMillis(); System.out.println("文件拷貝完成,耗時"+(endtime-begintime)+"毫秒"); }catch(Exception e){ System.out.println("文件操做失敗"); }finally{ try { in.close(); out.close(); } catch (IOException e) { e.printStackTrace(); } } }
}數據庫
對比設計模式
實驗內容:
1.寵物商店:在實驗八的基礎上,增長一個功能,用文件保存每日的交易信息記錄。數組
完成實驗內容,代碼上傳到碼雲,注意,寵物商店要求務必將建立數據庫的腳本文件隨項目文件一塊兒上傳,在隨筆中分析程序設計思路,用PowerDesigner畫出類圖結構,並對完成實驗內容過程當中遇到的問題、解決方案和思考等進行概括總結,注意代碼中必須有必要的註釋。
格式以下:函數
程序設計思路:
一、先設計一個PetItem類,包含number、name、age、cno、price屬性,並寫出get、set方法。設計一個Administrator類,包含name、mi屬性,並寫出get、set方法,編寫一個驗證方法。設計一個SellPetItem類,包含number、name、price、amount、money屬性,並寫出get、set方法。
二、設計一個JDBC類,方便AdminDao類往數據庫添加數據。
三、設計數據訪問AdminDao類,包含獲取全部數據,添加數據,刪除數據等方法。
四、設計服務AdminService類,包含查詢服務,添加服務,修改服務,刪除服務等方法,查詢服務要調用AdminDao類的queryAllData()方法,獲取全部數據。
五、設計WelcomeFrame類,聲明一個圖片組件和一個按鈕組件,設計一個設置窗體的函數,包括窗體大小、窗體位置、標題。添加組件方法,包括按鈕組件,標題組件。設計添加監聽器方法。設計一個顯示管理員界面方法,讓它鏈接到下一個界面。
六、設計Adminis類,聲明一個按鈕、兩個標籤,設計一個設置窗體的函數,包括窗體大小、窗體位置、。添加組件方法,包括按鈕組件,標題組件。設計添加監聽器方法。設計一個顯示管理員界面方法,讓它鏈接到下一個界面。設計一個修改的方法調用Administrator類的驗證方法。
七、設計系統管理界面, AdminDialog類,定義界面使用的組件,使用JTextField組件輸入文本,編寫構造方法,初始化方法,添加組件,添加監聽器,編寫查詢方法,調用adminService的查詢服務,編寫添加方法,刪除方法,修改方法。
八、編寫工具類,方便WelcomeFrame類調用。
九、設計主方法,調用WelcomeFrame().setVisible(true),運行項目。工具
類圖學習
2.完成文件複製操做,在程序運行後,提示輸入源文件路徑和目標文件路徑。this
程序設計思路:使用FileInputStream和FileOutputStream方法編寫,輸出語句提示用戶輸入源文件路徑和目標文件路徑。
碼雲commit歷史截圖
代碼行數(新增/累積) | 學習時間(新增/累積) | 本週學習內容 | |
---|---|---|---|
目標 | 5000行 | 300小時 | |
第2-4周 | 100/100 | 20/20 | 學習了數組和方法 |
第5周 | 200/300 | 30/50 | 學習了String類和StringBuffer類 |
第6周 | 800/1100 | 40/90 | 學習了this、static關鍵字,Singleton模式 |
第八週 | 1200/1700 | 60/110 | 繼承和多態,抽象方法 |
第九周 | 1500/2000 | 10/120 | 接口、工廠設計模式、包裝類、匿名內部類、日期類、正則表達式 |
第十週 | 1900/2400 | 10/130 | 異常處理、泛型、集合 |
第十一週 | 2500/3000 | 20/150 | 用戶圖形界面、事件處理 |
第十二週 | 500/3500 | 10/160 | JDBC數據庫的連接 |
第十三週 | 800/4300 | 50/210 | java io |