久久r热视频,国产午夜精品一区二区三区视频,亚洲精品自拍偷拍,欧美日韩精品二区

您的位置:首頁(yè)技術(shù)文章
文章詳情頁(yè)

JAVA文件讀寫例題實(shí)現(xiàn)過程解析

瀏覽:2日期:2022-08-30 10:30:47

練習(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)。

標(biāo)簽: Java
相關(guān)文章:
主站蜘蛛池模板: 兰西县| 宁波市| 扶沟县| 乌鲁木齐县| 安福县| 江都市| 金阳县| 普洱| 康保县| 石台县| 巢湖市| 满洲里市| 本溪市| 饶河县| 乌鲁木齐市| 新乡市| 阜新市| 昆明市| 丹阳市| 霍邱县| 拉萨市| 忻城县| 咸丰县| 东光县| 晋中市| 秦皇岛市| 甘孜县| 霍州市| 施甸县| 五指山市| 栾川县| 界首市| 呼图壁县| 河曲县| 丰宁| 屏山县| 大冶市| 历史| 祁门县| 光泽县| 和硕县|