版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
1、操作系統(tǒng)課程實(shí)驗(yàn)報(bào)告20132014年度 第1學(xué)期院系: 學(xué)號(hào):姓名:任課教師: 成績(jī)?cè)u(píng)定: 實(shí)驗(yàn)一題目:文件管理完成日期:年 月曰1、實(shí)驗(yàn)?zāi)康牧私馕募芾淼墓δ芎腿蝿?wù),理解文件系統(tǒng)組成和特點(diǎn),熟悉文件系統(tǒng)的訪問和操作。實(shí)驗(yàn)要求用高級(jí)語言編寫和調(diào)試一個(gè)簡(jiǎn)單的模擬文件管理程序。加深理解有關(guān)盤塊的分配與回收、目錄管理等的具體實(shí)施策略。2. 、實(shí)驗(yàn)內(nèi)容模擬一個(gè)資源管理器進(jìn)行文件操作,包括建立和刪除目錄、 建立和刪除文件等基本文件操作。建立相應(yīng)的數(shù)據(jù)結(jié)構(gòu)(如:位示圖等),模擬盤塊管理??梢詤⒄?qǐng)D 6界面進(jìn)行設(shè)計(jì)。地址:ijL fSO-戶我的電腦判上鄰居0=戸 Documents and Setting
2、sD回收站4 口新運(yùn)丈收、huan.txt、yao.tetI cc.ttt辛本地險(xiǎn)盤(D:)新建文件夾垂的療瀬時(shí)鋰誥宜石文件內(nèi)客擺改文忡容匱改立拌夾窯腳陸史件(滅)yaoixl文件ll- b:走一回.dor文件冨n-www.btl文件才,w.樂 b:321 txt立件:)b t:bb.M文件T z123.txt文件321 yl/1P030S633 rmvb文件bb M餞節(jié)笙記5 J VI123 .ktkpO3D6G33.r-bB6334)df55鷗知電記 口 DD3、算法設(shè)計(jì)1)、定義主面板MainFrame,布局好各個(gè)控件,并初始化/*往node節(jié)點(diǎn)下添加一個(gè)子節(jié)點(diǎn) obj;*/public
3、 void addChild(Object obj, DefaultMutableTreeNode node) if (obj != null & node != null) DefaultMutableTreeNode temp = new DefaultMutableTreeNode(obj);if (n ode.getAllowsChildre n()no de.add(temp);if (!(String) obj).equals(A: ) & (String) obj).length() = 3)/ 防止讀取 A軟 驅(qū),會(huì)出現(xiàn)異常 ;用于初始用的 ;addChildren( cmd.
4、listAll(String) obj), temp); /*在node節(jié)點(diǎn)下添加數(shù)組children;*/public void addChildren(String children, DefaultMutableTreeNode node) if (children != null & node != null ) for (int i = 0; i children. length; i+) addChild(childreni, node); /* 對(duì)樹的節(jié)點(diǎn)進(jìn)行預(yù)提取 ;*/public void addPrefetchChildren(String path, DefaultMu
5、tableTreeNode node) addChildren( cmd.listDirectory(path), node);/* 對(duì)路徑路徑進(jìn)行連接;(已經(jīng)獲得了所有的整個(gè)路徑,需要量轉(zhuǎn)化 )*/public String toFilePath(String str) / 先去掉頭尾的 ; String pa = str.substring(1, str.length() - 1); String temp = pa.split( , ); String path = ;for (int i = 1; i temp. length; i+) if (!path.endsWith() & !
6、path.equals( )/ 不為空是為去根節(jié)點(diǎn) path += ;path += tempi;return path;public String toPFilePath(String str) / 先去掉頭尾的 ; String pa = str.substring(1, str.length() - 1); String temp = pa.split( , ); String path = ;for (int i = 1; i temp, length - 1; i+) if (!path.endsWith() & !path.equals( )/ 不為空是為去根節(jié)點(diǎn) ;path +=
7、 ;path += tempi;return path;public classExpandListener implements TreeWillExpandListener /*樹展開及收縮監(jiān)聽;*/private MainF rame mainF rame = null;public Expa ndListe ner(Ma inF rame mainF rame) this.mai nF rame = mai nFrame;public void treeWillExpa nd(TreeExpa nsi onEvent eve nt) /對(duì)節(jié)點(diǎn)的路徑進(jìn)行轉(zhuǎn)化Stri ng path =
8、toFilePath(eve nt.getPath().toStri ng();TreePath treePath = even t.getPath();DefaultMutableTreeNode n ode = (DefaultMutableTreeNode) treePath.getLastPathComp onen t();/ System.out.println(” 所展開節(jié)點(diǎn)的路徑:+ path);/ System.out.pri ntln( treePath);if (n ode.getDepth() 2) Enu merati on childre n = no de.chil
9、dre n();Stri ng filePath =;while (childre n. hasMoreEleme nts() DefaultMutableTreeNode temp = (DefaultMutableTreeNode) childre n.n extEleme nt();filePath =;filePath = path;if (!filePath.endsWith( )filePath += ;filePath += temp.toStri ng();/ System.out.pri ntln (temp= +filePath);mainFrame.addPrefetch
10、Children(filePath, temp);2)、添加功能 添加文件(夾)addframe() ”、修改文件(夾) mvframe()”public void addframe() JFrame addFrame = new JFrame();JLabel jlbl = new JLabel(請(qǐng)輸入要添加的文件 (夾)名:”); addrs = new JLabel();addrs.setBounds(180, 10, 100, 25); jlbl.setBounds(10, 10, 170, 25);addfile = new JTextField(); addfile.setBoun
11、ds(10, 40, 260, 25); btnaddf = new JButton(添加文件”); btnaddd = new JButton(添加文件夾”); btnaddf.setBounds(20, 80, 100, 25); btnaddd.setBounds(160, 80, 100, 25); btnaddf.addAction Listener( this); btnaddd.addActionListener( this); addFrame.add(jlbl); addFrame.add(addrs); addFrame.add(addfile); addFrame.add
12、(btnaddf); addFrame.add(btnaddd);addFrame.setBounds(400, 350, 300, 150); addFrame.setTitle(” 添加文件(夾)”); addFrame.setLayout(null); addFrame.setVisible(true);public void mvframe() JFrame mvFrame = new JFrame();JLabel jlbl = new JLabel(請(qǐng)輸入修改后的文件名:”);mvrs = new JLabel(); mvrs.setBounds(160, 10, 140, 25)
13、; jlbl.setBounds(10, 10, 170, 25); mvfile = new JTextField(); mvfile .setBounds(10, 40, 260, 25); btnmvf = new JButton(修改文件名”); btnmvd = new JButton( 修改文件夾名 ); btnmvf.setBounds(10, 80, 120, 25); btnmvd .setBounds(150, 80, 120, 25); btnmvf.addActionListener( this); btnmvd.addActionListener( this); mv
14、Frame.add(jlbl);mvFrame.add(mvrs); mvFrame.add(mvfile ); mvFrame.add(btnmvf); mvFrame.add(btnmvd);mvFrame.setBou nds(400, 350, 300, 150);mvFrame.setTitle(修改文件(夾)名 ”);mvFrame.setLayout( null);mvFrame.setVisible( true);3)顯示文件*顯示系統(tǒng)中的所有盤符;public Stri ng ListDisks() File roots = File. listRoots();/ 根盤符;S
15、tring disks = new Stringroots. length;for (int i = 0; i roots. length; i+) disksi = rootsi.toStri ng();return disks;*獲得路徑path下的文件;public Strin g listAll(Stri ng path) try File f = new File(path);Stri ng fileName;Stri ng tmp = null;mainF rame.fileshow .setText(null);mainFrame.filestyle .setText(null)
16、;if (f.isDirectory() fileName = f.list();/ System.out.println(” 共有+ fileName.length + 個(gè)文件); for (int i = 0; i fileName. length; i+) mainF rame.fileshow .appe nd(fileNamei + n);tmp = path + + fileNamei;/ System.out.pri ntln( tmp);if (listDirectory(tmp) != null) mainFrame.filestyle .append(”文件夾 n”); e
17、lsemainFrame.filestyle .append(”文件 n);return fileName; elseif (f.isFile() System.out.println(這是一個(gè)文件);return null; else / System.out.pri ntln( path);return null; catch (Excepti on e) return null;public Strin g listDirectory(Stri ng path) File f = new File(path);Stri ng fileName;if (f.isDirectory() fi
18、leName = f.list();return fileName; else / System.out.println(path + 是文件);return null;*進(jìn)行md操作;md 功能:創(chuàng)建新目錄public void md(String directory) if (! mai nF rame.curre ntPath.equals() Stri ng temp = mainF rame .curre ntPath + + directory;File n ewFile = new File(temp);if (!n ewFile.exists() try if (n ewFil
19、e.isDirectory() = false) n ewFile.mkdirs();System.out.println(文件夾創(chuàng)建成功!); elseSystem.out.println(文件夾創(chuàng)建出錯(cuò)!); catch (Excepti on e) System.out.println(出錯(cuò)信息:+ e.getMessage(); else System.out.println(文件夾已經(jīng)存在);*進(jìn)行rd操作;rd 功能:刪除目錄;public void del() String temp = mainF rame .curre ntPath;File file = new File(
20、temp);if (file.exists() if (file.delete() mainFrame.fileshow .setText(”文件(夾)刪除成功!); else mainFrame.fileshow .setText(文件(夾)刪除操作出錯(cuò)!); else ma in Frame.fileshow .setTextf 文件(夾)不存在);/*進(jìn)行edit操作:edit 功能:新建文件*/public void edit(String file) if (!mainFrame.currentPath.equals() String temp = mainFrame.current
21、Path + + file;File newFile = new File(temp);if (newFile.exists() mai nF rame.addrs.setText(文件已經(jīng)存在!”);System.out.println(文件已經(jīng)存在!); else try newFile.createNewFile();ma in Frame.addrs.setText(” 文件創(chuàng)建成功!”);System .out .println( 文件創(chuàng)建成功 !); catch (Exception e) System .out .println( 文件創(chuàng)建失敗 : + e.getMessage(
22、);public void mvf(String file)if (!mainFrame.PPath.equals() String temp = mainFrame.PPath + + file;File newFile = new File(mainFrame.currentPath);if (newFile.exists() if(newFile.renameTo(new File(temp)= true )mai nFrame.mvrs.setText(” 修改文件名成功!”); elsemai nFrame.mvrs.setText(” 存在同名文件!”);public void m
23、vd(String dir)if (! mai nFrame .P Path.equals() Stri ng temp = mai nFrame.PPath + + dir;File newFile = new File( mainFrame.currentPath);if (n ewFile.exists() if (n ewFile.re nameTo( new File(temp)= true)mai nF rame. mvrs .setText(修改文件夾名成功!); elsemai nFrame.mvrs.setText(” 存在同名文件夾!”);4、運(yùn)行與測(cè)試運(yùn)行時(shí),彈出主界面技
24、的電昕匚j我的立禪胡器C3 ,回 S3 X-別新當(dāng)前目錄雙擊文件盤Cr毎的丈隹音逗蠱I File Help地址:c 3a JDaDDDDD.QDDDSD 一 一 一 . .-*1- - 1111- 一 一 一 一OKS(K嶼S360SectionSRecyde Bin 360S*rJDBOX autoexec. t)atBoot bootmgr B00T3ECTBAKCFLogconfig.sysDocuments and Scitings errcr.txtFetioriBo*ha.lxtIntelIO.SYSMSDOSSYSMSOCacheOEMSF刪瞭交件(夾)刷新當(dāng)前目錄I幡改文件僕沼
25、 I在E盤路徑添加文件夾操作系統(tǒng),再添加文件操作系統(tǒng)JLabel jlbl = new JLabel mvrs new JLabel (t,w);mvrs srtBounds(160/ 10, 140r 25); jlblse匸bounds(10, 10z 170z 25); mvfile = new JTextField(): ravfile.setBounds(10, 40r 260, 25); | btnmvf new JBucton (R 修改文件名 T; btnmvd = new JBurcon (R 修改文件夾名* brnmvfse匸Bounds(10, 30, 120, 25); btnmvdsetBounds(150. 80, 120, 25); btnmvf addActionListener(this); btnmvd.aiddActionListener (this); mvFrame add (j lbl.);mvFraineadd (mvrs);File Help地址: E:請(qǐng)範(fàn)入要添加的文件俠肉:燥作裁導(dǎo)我的電肪O-C3 C:C3 D:? 曰a (3 SRECYCLE.BINPl System Volume Information文件凸畢業(yè)照o-3 fa G
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 2024年云南客運(yùn)考試應(yīng)用能力試題題庫答案
- 冷凍冷藏集裝箱租賃行業(yè)發(fā)展前景及投資風(fēng)險(xiǎn)預(yù)測(cè)分析報(bào)告
- 2024年江蘇客運(yùn)從業(yè)資格證考試答案
- 2024年上海客運(yùn)資格證必考題
- 2024年杭州2024年客運(yùn)資格證仿真考試
- 無界零售科技行業(yè)市場(chǎng)發(fā)展趨勢(shì)及投資咨詢報(bào)告
- 2024年蘭州客運(yùn)資格證培訓(xùn)考試題版
- 質(zhì)量員-市政方向-基礎(chǔ)(質(zhì)量員)題庫及答案
- 廢棄物資源化利用行業(yè)市場(chǎng)發(fā)展趨勢(shì)及投資咨詢報(bào)告
- 甘肅省隴南市西和縣2022-2023學(xué)年九年級(jí)上學(xué)期期末語文試題
- (新版)云南水利安全員(B證)考試題庫-下(多選、判斷題)
- 2024反詐知識(shí)競(jìng)賽考試題庫及答案(三份)
- 雅馬哈RX-V365使用說明書
- 嚴(yán)重精神障礙患者管理服務(wù)規(guī)范培訓(xùn)課件
- 陽光食品APP培訓(xùn)考核題庫(含答案)食品生產(chǎn)企業(yè)端
- 廣元市2024年專業(yè)技術(shù)人員公需科目繼續(xù)教育試卷及參考答案
- 《百分?jǐn)?shù)(一)》大單元教學(xué)設(shè)計(jì)
- 村衛(wèi)生室靜脈輸液規(guī)范和安全管理制度
- SJ-T 3328.1-2016 電子產(chǎn)品用高純石英砂 第1部分 技術(shù)條件
- 《蟲兒飛》幼兒園大班音樂教案范例
- 10、初中數(shù)學(xué).立體圖形的展開圖.第10講.教師版
評(píng)論
0/150
提交評(píng)論