JAVA文件讀寫(xiě)例題實(shí)現(xiàn)過(guò)程解析
練習(xí)
有這樣的一個(gè)words數(shù)組,數(shù)組中每個(gè)字符串的格式為“詞性:單詞”
String[] words = {'verb:eat','verb:drink','verb:sleep','verb:play','noun:rice','noun:meat','noun:hand','noun:hair'};
根據(jù)單詞性質(zhì)動(dòng)詞verb全部存入verb.txt文件中
根據(jù)單詞性質(zhì)名詞noun全部存入noun.txt文件中
package readandwrite;/*1.有這樣的一個(gè)words數(shù)組,數(shù)組中每個(gè)字符串的格式為“詞性:單詞” String[] words = {'verb:eat','verb:drink','verb:sleep','verb:play','noun:rice','noun:meat','noun:hand','noun:hair'}; 根據(jù)單詞性質(zhì)動(dòng)詞verb全部存入verb.txt文件中 根據(jù)單詞性質(zhì)名詞noun全部存入noun.txt文件中*/import java.io.*;public class FileReadAndWrite { public static void main(String args[]) throws IOException { //WORDS數(shù)組 String[] words = {'verb:eat','verb:drink','verb:sleep','verb:play','noun:rice','noun:meat','noun:hand','noun:hair'}; FileOutputStream outFile1 = new FileOutputStream('verb.txt'); FileOutputStream outFile2 = new FileOutputStream('noun.txt'); OutputStream out1 = new BufferedOutputStream(outFile1); OutputStream out2 = new BufferedOutputStream(outFile2); for(int i=0;i<words.length;i++){ if(words[i].startsWith('verb')){byte[] bytes1 = words[i].getBytes();out1.write(bytes1); } if(words[i].startsWith('noun')){byte[] bytes2 = words[i].getBytes();out2.write(bytes2); } } out1.close(); out2.close(); }}
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持好吧啦網(wǎng)。
相關(guān)文章:
1. jsp實(shí)現(xiàn)登錄驗(yàn)證的過(guò)濾器2. Xml簡(jiǎn)介_(kāi)動(dòng)力節(jié)點(diǎn)Java學(xué)院整理3. phpstudy apache開(kāi)啟ssi使用詳解4. ASP.NET MVC使用異步Action的方法5. 爬取今日頭條Ajax請(qǐng)求6. jsp文件下載功能實(shí)現(xiàn)代碼7. ajax實(shí)現(xiàn)頁(yè)面的局部加載8. AJAX的跨域問(wèn)題解決方案9. uni-app結(jié)合.NET 7實(shí)現(xiàn)微信小程序訂閱消息推送10. 利用ajax+php實(shí)現(xiàn)商品價(jià)格計(jì)算
