




版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
1、第h章:java io編程11.1文件操作類:file范例11-1:文件基本操作。任意給定一個(gè)文件路徑,如果文件不存在則創(chuàng)建一個(gè)新的文件,如果文件存在則將文件刪除。package com.yootk.demo;import java.io.file;public class testdemo public static void main(string args) throws exception file file = new file(hd:test.txth);if (file.exists() file.delete(); else system. println(file.creat
2、enewfile();/此處直接拋岀/設(shè)置文件的路徑/判斷文件是否存在/刪除文件ii文件不存在/創(chuàng)建新文件范例笛2 :創(chuàng)建帶路徑的文件。如果給定的路徑為根路徑,則文件可以直接利用createnewfile()方法進(jìn)行創(chuàng)建;如果要?jiǎng)?chuàng)建的文件存在目錄,那么將 無(wú)法進(jìn)行創(chuàng)建。所以合理的做法應(yīng)該是在創(chuàng)建文件前判斷父路徑(getparent()取得父路徑)是否存在,如果不存在則應(yīng)該 先創(chuàng)建目錄(mkdirs()創(chuàng)建多級(jí)目錄),再創(chuàng)建文件。包含路徑的文件創(chuàng)建如圖所示。package com.yootk.demo;import java.io.file;public class testdemo publi
3、c static void main(string args) throws exception / 此處直接拋出file file = new file(hd:h + fie.separator + "demo” + fe.separator+ ” hello" + fwe. separator + myootkm + fwe. separator+ htest.txr);/設(shè)置文件的路徑if (!file.getparentfile().exists() file.getparentfile().mkdirs();system.ot/zprintl n(file.cre
4、atenewfile();/現(xiàn)在父路徑不存在/創(chuàng)建父路徑/創(chuàng)建新文件范例11-3 :取得文件或目錄的信息。package com.yootk.demo;import java.io.file;import java.math.bigdecimal;import java.text.simpledateformat;import java.util.date;public class testdemo public static void main(string args) throws exception / 此處直接拋出 file file = new file(hd:m + fe.sepa
5、rator + ,my.jpgm); / 設(shè)置文件的路徑 if (file.exists() system.owprintlnf1 是否是文件:"+ (file.isfile();system.ofprintln(”是否是目錄:” + (file.isdirectory();文件大小是按照字節(jié)單位返回的數(shù)字,所以需要將字節(jié)單元轉(zhuǎn)換為兆(m)的單元/但是考慮到小數(shù)點(diǎn)問(wèn)題,所以使用bigdecimal處理system.owprintln(”文件大小:h+ (new bigdecimal(double) file.length() / 1024 / 1024).divide(new big
6、decimal(l), 2,bgdecima.round_half_up) + "m");/返回的日期是以long的形式返回,可以利用simpledateformat進(jìn)行格式化操作system.oprintlnc上次修改時(shí)間:11+ new simpledateformat("yyyy-mm-dd hh:mm:ssn).format(new date(file.lastmodified();/判斷當(dāng)前路徑是否為目錄/ 調(diào)用tostring()package com.yootk.demo;import java.io.file;public class testde
7、mo public static void main(stringq args) throws exception / 此處直接拋出file file = new filecc:'1 + fwe.separator if (file.isdirectoryo) file result = file.listfiles();for (int x = 0; x < resultength; x+) syste m. println(resultx);范例11-5:列出指定目錄下的所有文件及子目錄信息。在每一個(gè)目錄 中有可能還會(huì)存在其他子目錄,并且還可能有更深層次的子目錄,所 以為了可
8、以列出所有的內(nèi)容,應(yīng)該判斷每一個(gè)給定的路徑是否是目 錄。如果是目錄則應(yīng)該繼續(xù)列出,這樣的操作最好使用遞歸的方式完 成。package com.yootk.demo;import java.io.file;public class testdemo public static void main(stringo args) throws exception / 此處直接拋出file file = new file(hc:" + file.separator p加(file);/定義操作路徑/列出目錄*列岀目錄結(jié)構(gòu),此方法采用遞歸調(diào)用形式* param file要列出目錄的路徑7publ
9、ic static void print(file file) if (file.isdirectoryo) file result = file.listfiles();if (result != null) for (int x = 0; x < resultength; x+) p別 resultx);system. tjt/zpri ntln (file);/路徑為目錄/列出子目錄/目錄可以列出/遞歸調(diào)用/直接輸岀完整路徑11.2字節(jié)流與字符流范例11-6 :自動(dòng)執(zhí)行close。操作。字節(jié)流與字符流package com.yootk.demo;class net implemen
10、ts autocloseable overridepublic void close() throws exception sys怕m.06/.println(h*網(wǎng)絡(luò)資源自動(dòng)關(guān)閉,釋放資源。h);public void info() throws exception / 假設(shè)有異常拋出system.o(/aprintln(w* 歡迎訪問(wèn):”);public class testdemo public static void main(string args) try (net n = new net()(); catch (exception e) e.printstacktra
11、ce();package com.yootk.demo;import java.io.file;import java.io.fileoutputstream;import java.io.outputstream;public class testdemo public static void main(string args) throws exception / 直接拋出/1.定義要輸出文件的路徑file file = new file(hd:n + fwe.separator + “demo” + fe.separator+ hmldn.txtn);此時(shí)由于目錄不存在,所以文件不能輸岀
12、,應(yīng)該首先創(chuàng)建目錄if (!file.getparentfile().exists() / 文件目錄不存在ii2.應(yīng)該使用outputstream和其子類進(jìn)行對(duì)象的實(shí)例化,此時(shí)目錄存在,文件還不存在 outputstream output = new fileoutputstream(file);字節(jié)輸出流需要使用byte類型,罷要將string類對(duì)象變?yōu)樽止?jié)數(shù)組string str ="更多課程資源請(qǐng)?jiān)L問(wèn):”;byte datao = str.getbytes();/將字符串變?yōu)樽止?jié)數(shù)組output.write(data);3 輸出內(nèi)容output.close();/4 .資源操作
13、的最后一定要進(jìn)行關(guān)閉/2應(yīng)該使用outputstream和其子類進(jìn)行對(duì)象的實(shí)例化,此時(shí)目錄存在,文件還不存在 outputstream output = new fileoutputstream(file,true);范例11-9 :采用單個(gè)字節(jié)的方式輸出(此處可以利用循環(huán)操作輸出 全部字節(jié)數(shù)組中的數(shù)據(jù))。for (int x= 0 ; x < dataength ; x +) output.write(datax);/ 內(nèi)容輸出范例11-10 :輸出部分字節(jié)數(shù)組內(nèi)容(設(shè)置數(shù)組的開始索引和長(zhǎng)度)。/內(nèi)容輸出output.write(data, 6, 6);范例11-11:數(shù)據(jù)讀取操作。p
14、ackage com.yootk.demo;import java.io.file;import java.io.fileinputstream;import java.io .in putstream;public class testdemo public static void main(stringq args) throws exception / 直接拋出file file = new filef'd:" + fie.separator + "demo” + fwe.separator+ ,mldn.txtm);/1 .定義要輸出文件的路徑if (fil
15、e.existso) /需要判斷文件是否存在后才可以進(jìn)行讀取/ 2 .使inputstream進(jìn)行讀取in putstream in put = new filel nputstream(file);byte data = new byte 1024;ii 準(zhǔn)備出一個(gè) 1024的數(shù)組int len = input.read(data);ii3 .進(jìn)行數(shù)據(jù)讀取,將內(nèi)容保存到字節(jié)數(shù)組中input.close();/4 .關(guān)閉輸入流/將讀取出來(lái)的字節(jié)數(shù)組數(shù)據(jù)變?yōu)樽址M(jìn)行輸出system.o6/zprintln(" " + new string(data,ojen) + &quo
16、t; m);范例11-12 :采用while循環(huán)實(shí)現(xiàn)輸入流操作。package com.yootk.demo;import java.io.file;import java.io.filelnputstream;import java.io .in putstream;public class testdemo public static void main(stringq args) throws exception / 直接拋出file file = new filefd:" + fe.separator + "demo” + fe.separator+ ,mldn.t
17、xtn);/1 .定義要輸出文件的路徑if (file.existso) /需要判斷文件是否存在后才可以進(jìn)行讀取/ 2使inputstream進(jìn)行讀取inputstream input = new filelnputstream(file);byte data = new byte 1024;/ 準(zhǔn)備出一個(gè) 1024的數(shù)組intfoot = 0;/表示字節(jié)數(shù)組的操作腳標(biāo)inttemp = 0;/表示接收每次讀取的字節(jié)數(shù)據(jù)/第一部分:(temp = input.read(),表示將read()方法讀取的字節(jié)內(nèi)容給temp變量/第二部分:(temp = input.read() != -1 ,判斷
18、讀取的temp內(nèi)容是否是 while(temp = input.read() != -1) / 3 .讀取數(shù)據(jù)datafoot + = (byte) temp ;/ 有內(nèi)容進(jìn)行保存input.close();/ 4 .關(guān)閉輸入流system.0zprintln(" " + new string(data,0,foot) + "");范例11-13 :利用do.while實(shí)現(xiàn)數(shù)據(jù)讀取。byte data = new byte 1024; int foot = 0 ;int temp = 0 ;dotemp = input.read();if (temp !
19、= -1) /準(zhǔn)備出一個(gè)1024的數(shù)組/表示字節(jié)數(shù)組的操作腳標(biāo)/表示接收每次讀取的字節(jié)數(shù)據(jù)/讀取一個(gè)字節(jié)/現(xiàn)在是真實(shí)的內(nèi)容datafoot + = (byte) temp ; /保存讀取的字節(jié)到數(shù)組中 while (temp != -1);/如果現(xiàn)在讀取的temp的字節(jié)數(shù)據(jù)不是邛,表示還有內(nèi)容范例11-14 :使用writer類實(shí)現(xiàn)內(nèi)容輸出package com.yootk.demo;import java.io.file;import java.io.filewriter;import java.io.writer;public class testdemo public static vo
20、id main(string args) throws exception / 此處直接拋出file file = new filef'd:" + fie.separator + “demo” + file.separator+ "mldn.txt");/1 .定義要輸出文件的路徑if (!file.getparentfile().exists() /判斷目錄是否存在file.getparentfile().mkdirs();/創(chuàng)建文件目錄writer out = new filewriter(file);/ 2 實(shí)例化了 writer類的對(duì)象string
21、 str = ”更多課程請(qǐng)?jiān)L問(wèn):”; /定義輸出內(nèi)容 out.write(str);/3 .輸出字符串?dāng)?shù)據(jù)out.close();/4 .關(guān)閉輸出流范例11-15 :使用reader讀取數(shù)據(jù)。package com.yootk.demo;import java.io.file;import java.io.filereader;import java.io.reader;public class testdemo public static void main(stringo args) throws exception / 此處直接拋出file file = new file(hd:h +
22、file.separator + "demo” + fwe.separator+ ,mldn.txth);if (file.exists() reader in = new filereader(file); char data q = new char 1024; int len 二 in.read(data); in.close();定義要輸出文件的路徑/2 .為reader類對(duì)象實(shí)例化ii開辟字符數(shù)組,接收讀取數(shù)據(jù)/ 3 .進(jìn)行數(shù)據(jù)讀取4關(guān)閉輸入流system.ozprintln(new string(dataf 0, len); 范例11-16 :強(qiáng)制清空字符流緩沖區(qū)。pac
23、kage com.yootk.demo;import java.io.file;import java.io.filewriter;import java.io.writer;public class testdemo public static void main(string args) throws exception / 此處直接拋出file file = new file(nd:n + file.separator + "demo” + separator+ "mldn.txt”);/1 .定義要輸出文件的路徑if (!file.getparentfile().e
24、xists() / 判斷目錄是否存在file.getparentfile().mkdirs();/ 創(chuàng)建文件目錄writer out = new filewriter(file);/ 2 .實(shí)例化了 writer類的對(duì)象string str ="更多課程請(qǐng)?jiān)L問(wèn):" /定義輸出內(nèi)容 out.write(str);/3 .輸出字符串?dāng)?shù)據(jù)out.flush();/強(qiáng)制刷新緩沖區(qū)11.3轉(zhuǎn)換流范例11-17 :實(shí)現(xiàn)輸出流轉(zhuǎn)換。package com.yootk.demo;import java.io.file;import java.io.fileoutputstream;impo
25、rt java.io.outputstream;import java.io.outputstreamwriter;import java.io.writer;public class testdemo public static void main(stringo args) throws exception / 此處直接拋出file file = new file(hd:n + fe.separator + "demo” + fe.separator+ "mldn.txt");/1 .定義要輸出文件的路徑if (!file.getparentfile().ex
26、ists() /判斷父路徑是否存在file.getparentfile().mkdirs();/創(chuàng)建父路徑outputstream output = new fileoutputstream(file);/ 字節(jié)流/將outputstream類對(duì)象傳遞給outputstreamwriter類的構(gòu)造方法,而后向上轉(zhuǎn)型為writerwriter out = new outputstreamwriter(output);out.write(n更多課程請(qǐng)?jiān)L問(wèn):www.yootk.corrt);/ writer類的方法out.flush();out.close();11.4案例:文件復(fù)制范例巧:實(shí)現(xiàn)文件
27、復(fù)制操作。package com.yootk.demo;import java.io.file;import java.io.filelnputstream;import java.io.fileoutputstream;import java.io .in putstream;import java.io.outputstream;public class copydemo public static void main(stringo args) throws exception long start = system.currentt/mem/is(); if (args.length
28、!= 2) system.omprintlnc命令執(zhí)行錯(cuò)誤! ”);/取得復(fù)制開始的時(shí)間/初始化參數(shù)不足2位system .ex/");/程序退岀執(zhí)行ii如果輸入?yún)?shù)正確,應(yīng)該進(jìn)行源文件有效性的驗(yàn)證file infile = new file(argso); if (!infile.exists() /第一個(gè)為源文件路徑/源文件不存在system.o£/.println(h源文件不存在.請(qǐng)確認(rèn)執(zhí)行路徑。h);system, ex/1);/程序退出/如果此時(shí)源文件正確,就需要定義輸岀文件,同時(shí)要考慮到輸岀文件有目錄file outfile = new file(args1);
29、if (!outfile.getparentfile().exists() outfile.getparentfile().mkdirs();/輸出文件路徑不存在/創(chuàng)建目錄/實(shí)現(xiàn)文件內(nèi)容的復(fù)制,分別定義輸岀流與輸入流對(duì)象inputstream in put = new filelnputstream(infile);outputstream output = new fileoutputstream(outfile);int temp = 0 ;/保存每次讀取的數(shù)據(jù)長(zhǎng)度byte data = new byte 1024;/每次讀取1024個(gè)字節(jié)/將每次讀取進(jìn)來(lái)的數(shù)據(jù)保存在字節(jié)數(shù)組里面,并且返回
30、讀取的個(gè)數(shù)while(temp = input.read(data) != -1) /循環(huán)讀取數(shù)據(jù)output.write(data, 0, temp);i/輸出數(shù)組in put.close();/關(guān)閉輸入流output.close();/關(guān)閉輸出流long end = system. currenttimemillis ;/取得操作結(jié)束時(shí)間system.mprintln("復(fù)制所花費(fèi)的時(shí)間:"+ (end -start);11.5字符編碼范例11-19 :取得當(dāng)前系統(tǒng)中的環(huán)境屬性中的文件package com.yootk.demo;public class testdem
31、o public static void main(stringq args) throws exception sys 怕 m .ge 滬廠opeh/'esq. i ist(system. out);列出全部系統(tǒng)屬性范例11-20 :程序出現(xiàn)亂碼。package com.yootk.demo;import java.io.file;import java.io.fileoutputstream;import java.io.outputstream;public class testdemo public static void main(string args) throws ex
32、ception file file = new file(hd:h + separator mmldn.txth);outputstream output = new fileoutputstream(file);/強(qiáng)制改變文字的編碼,此操作可以通過(guò)string類的getbytes()方法實(shí)現(xiàn) output.write(”更多課程請(qǐng)?jiān)L問(wèn):www.yootk.cornm.getbytes(miso8859-1m); output.close();11-6內(nèi)存流范例11-21 :實(shí)現(xiàn)一個(gè)小寫字母轉(zhuǎn)大寫字母的操回豐 作。本程序不使用string類中提供的touppercase()方法,而是利用i0操
33、作,將每一個(gè)字節(jié)進(jìn)行大寫字母轉(zhuǎn)換; 為了方便地實(shí)現(xiàn)字母的轉(zhuǎn)大寫操作(避免不必要的字符也被轉(zhuǎn)換)可以借助character包裝類的方法。|-轉(zhuǎn)小寫字母:public static char tolowercase(char ch);|-轉(zhuǎn)小寫字母(利用字母編碼轉(zhuǎn)換):public static int tolowercase(int codepoint);|-轉(zhuǎn)大寫字母:public static char touppercase(char ch);|-轉(zhuǎn)大寫字母(利用字母編碼轉(zhuǎn)換):public static int touppercase(int codepoint)opackage com
34、.yootk.demo;import java.io.bytearrayl nputstream;import java.io.bytearrayoutputstream;import java.i on putstream;import java.io.outputstream;public class testdemo public static void main(stringo args) throws exception / 此處直接拋出string str = h & www.mldn.crt; / 要求被轉(zhuǎn)換的字符串/本次將通過(guò)內(nèi)存操作流實(shí)現(xiàn)轉(zhuǎn)換,先將數(shù)據(jù)保存在內(nèi)存流里面
35、,再?gòu)睦锩嫒〕雒恳粋€(gè)數(shù)據(jù)/將所有要讀取的數(shù)據(jù)設(shè)置到內(nèi)存輸入流中,本次利用向上轉(zhuǎn)型為inputstream類實(shí)例化inputstream in put = new bytearrayl nputstream(str.getbytes();/為了能夠?qū)⑺械膬?nèi)存流數(shù)據(jù)取岀,可以使用bytearrayoutputstreamoutputstream output = new bytearrayoutputstream();int temp = 0;/讀取每一個(gè)字節(jié)數(shù)據(jù)/經(jīng)過(guò)此次循環(huán)后,所有的數(shù)據(jù)都將保存在內(nèi)存輸出流對(duì)象中while (temp = input.read() != -1) / 每次讀取
36、一個(gè)數(shù)據(jù)/將讀取進(jìn)來(lái)的數(shù)據(jù)轉(zhuǎn)換為大寫字母f利用character.touppercase()可以保證只轉(zhuǎn)換字母output.write(character./<7t?perc5se(temp); / 字節(jié)輸出流/調(diào)用tostring()方法/關(guān)閉輸入流package com.yootk.demo;import java.io.bytearrayoutputstream;import java.io.file;import java.io.fileinputstream;import java.i on putstream;public class testdemo public stat
37、ic void main(string args) throws exception file filea = new filefd:'1 + fwe.separator + ,infoa.txtn);file fileb = new file(nd:h + fe.separator + minfob.txt");inputstream inputa = new filelnputstream(filea);inputstream inputb = new filelnputstream(fileb);bytearrayoutputstream output = new by
38、tearrayoutputstream(); int temp = 0;while (temp = inputa.read() != -1) output.write(temp);while (temp = inputb.read() != -1) output.write(temp);/異常簡(jiǎn)化處理/文件路徑ii文件路徑/字節(jié)輸入流/字節(jié)輸入流ii內(nèi)存輸出流ii每次讀取一個(gè)字節(jié)/循環(huán)讀取數(shù)據(jù)/將數(shù)據(jù)保存到輸出流/循環(huán)讀取數(shù)據(jù)/將數(shù)據(jù)保存到輸出流/現(xiàn)在所有的內(nèi)容都保存在了內(nèi)存輸出流里面,所有的內(nèi)容變?yōu)樽止?jié)數(shù)組取出byte data = output.tobytearray(); output.
39、close();in puta.close();inputb.close();system.o£/zprintln(new strin g(data);ii取出全部數(shù)據(jù)ii關(guān)閉輸出流ii關(guān)閉輸入流/關(guān)閉輸入流/字節(jié)轉(zhuǎn)換為字符串輸出11.7打印流范例11-23 :定義打印流工具類package com.yootk.demo;import java.io.file;import java.io.fileoutputstream;import java.i ooexcepti on;import java.io.outputstream;class printutil /實(shí)現(xiàn)專門的輸出操作
40、功能private outputstream output;ii 輸出只能依靠outputstream/*輸出流的輸出目標(biāo)要通過(guò)構(gòu)造方法傳遞* param outputtpublic printutil(outputstream output) this.output = output;public void print(lnt x) / 輸出 int型數(shù)據(jù)this.print(string.valueofl)/調(diào)用本類字符串的輸出方法public void print(string x) try /采用outputstream類中定義的方法,將字符串轉(zhuǎn)變?yōu)樽止?jié)數(shù)組后輸出 this.outpu
41、t.write(x.getbytes(); catch (loexception e) e.printstacktrace();public void print(double x) this.print(string. valueof/)public void println(int x) this.println(string. valueoh)public void println(string x) thls.print(x.concat(l,n,');public void println(double x) this.println(string. va!ueo/)publ
42、ic void close() try this.output.close(); catch (loexception e) e.pri ntstacktrace();public class testdemo public static void main(string args) throws exception / 此處直接拋出printutil pu = new printutil(new fileoutputstream(new filefd:11+ fe. separator + hyootk.txtu);pu.print("優(yōu)拓教育:");pu.println
43、(,');pu.println(1 + 1);pu.println(1.1 + 1.1);pu.close();/輸出double型數(shù)據(jù)/輸岀數(shù)據(jù)后換行輸出數(shù)據(jù)后換行/輸出流關(guān)閉范例11-24 :使用printstream類實(shí)現(xiàn)輸出。package com.yootk.demo;import java.io.file;import java.io.fileoutputstream;import java.io.printstream;public class testdemo public static void main(string args) throws exception /
44、 此處直接拋出/實(shí)例化printstream類對(duì)象,本次利用fileoutputstream類實(shí)例化printstream類對(duì)象printstream pu = new printstream(new fileoutputstream(new file(hd:m+ fie. separator + ” yootk.txt");pu.print(”優(yōu)拓教育:h);pu.println(,h);pu.println(1 + 1);pu.println(1.1 + 1.1);pu.close();package com.yootk.demo;import java.io.file;impo
45、rt java.io.fileoutputstream;import java.io.printstream;public class testdemo public static void main(stringo args) throws exception / 此處直接拋出 string name = ”李興華:int age = 19;double score = 59.95891023456;printstream pu = new printstream(new fileoutputstream(new filef'd:'* + fe. separator +
46、39;'yootk.txf');pu.printf(m姓名:%s ,年齡:%d ,成績(jī):%5.2f name, age, score); pu.close();package com.yootk.demo;public class testdemo public static void main(string args) throws exception string name = ”李興華:int age = 19;double score = 59.95891023456;string str = string, format'姓名:%s r 年齡:%d f 成績(jī):
47、%5.2f name, age, score);syste m. oprintln(str);11.8 system類對(duì)io的支持package com.yootk.demo; public class testdemo public static void main(string args) throws exception tryi nieger.parse/nt(''a be”);此處一定會(huì)發(fā)生異常 catch (exception e) system.e/rprintln(e); / 錯(cuò)誤輸出范例笛2:利用outputstream實(shí)現(xiàn)屏幕輸出。package com.y
48、ootk.demo;import java.io.outputstream;public class testdemo public static void main(string args) throws exception outputstream out = system .out、 out.write(hh.getbytes();/此處直接拋出異常/ outputstream就為屏幕輸出/屏幕輸出范例11-29 :消費(fèi)型函數(shù)式接口與方法引用。package com.yootk.demo;import java.util.function.consumer;此處直接拋岀/方法引用/輸出p
49、ublic class testdemo public static void main(string args) throws exception consumer<string> con = system.o加:println; con.acceptf1 更多課程請(qǐng)?jiān)L問(wèn):1');范例11-30 :實(shí)現(xiàn)鍵盤的數(shù)據(jù)輸入。package com.yootk.demo;import java.io .in putstream;public class testdemo public static void main(string args) throws exception /
50、 此處直接拋岀/為了方便讀者理解,本處將system.in使用inputstream接收,但實(shí)際上不需要此操作 inputstream input = system.zrz;/ system.in為 inputstream類實(shí)例byte data = new byte1024;/ 開辟空間接收數(shù)據(jù)system.“/.print("請(qǐng)輸入數(shù)據(jù):");/信息提示,此處沒有換行int len = input.read(data);/讀取數(shù)據(jù)并返回長(zhǎng)度system.omprintln(”輸入數(shù)據(jù)為:h + new string(data, 0, len);范例11-31 :改進(jìn)輸入
51、操作設(shè)計(jì)。package com.yootk.demo; import java.io .in putstream;public class testdemo public static void main(string args) throws exception / 此處直接拋出異常inputstream in put = system in; stringbuffer but = new stringbuffer(); system.omprint("請(qǐng)輸入數(shù)據(jù):"); int temp = 0;while (temp = input.read() != -1) if
52、 (temp = 'n') break; buf.append(char) temp);/接收輸入數(shù)據(jù)/提示信息/接收每次讀取數(shù)據(jù)長(zhǎng)度/判斷是否有輸入數(shù)據(jù)/判斷是否為回車符/停止接收/保存讀取數(shù)據(jù)/輸出內(nèi)容11.9字符緩沖流:uffered reader范例11-32 :鍵盤數(shù)據(jù)輸入的標(biāo)準(zhǔn)格式。system.owprintln("輸入數(shù)據(jù)為:"+ buf);package com.yootk.demo;import java.io.bufferedreader;import java.i on putstreamreader;public class testdemo public static void main(string args) throws exception / 此處直接拋出/ system.inmlnputs
溫馨提示
- 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(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ì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 城管洪災(zāi)搶險(xiǎn)方案(3篇)
- 內(nèi)部審計(jì)面試題及答案
- 現(xiàn)代車輛收售方案
- 甲狀腺手術(shù)并發(fā)癥
- 場(chǎng)監(jiān)督管理局建設(shè)項(xiàng)目施工許可合同示范文本
- 期權(quán)產(chǎn)品面試題及答案
- 綏化中考試題及答案
- 北方小區(qū)綠化改造方案
- 銷售內(nèi)勤考試題及答案
- 票務(wù)崗位面試題及答案
- 急性胃腸炎的護(hù)理查房
- 第一章-護(hù)理學(xué)基礎(chǔ)緒論
- 煙花爆竹經(jīng)營(yíng)單位安全管理人員培訓(xùn)教材課件
- J波與J波綜合征課件
- 微整面部美學(xué)設(shè)計(jì)面部風(fēng)水設(shè)計(jì)課件
- 5噸龍門吊安裝與拆除專項(xiàng)施工方案
- 康復(fù)科護(hù)理質(zhì)量監(jiān)測(cè)指標(biāo)
- 農(nóng)藥基本常識(shí)課件
- 六年級(jí)數(shù)學(xué)分?jǐn)?shù)除法、解方程計(jì)算題 (含答案)
- 高速鐵路竣工驗(yàn)收辦法
- 擬投入公路工程施工設(shè)備檢測(cè)儀器設(shè)備表
評(píng)論
0/150
提交評(píng)論