国产成人精品亚洲777人妖,欧美日韩精品一区视频,最新亚洲国产,国产乱码精品一区二区亚洲

您的位置:首頁技術文章
文章詳情頁

JAVA文件讀寫例題實現過程解析

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

練習

有這樣的一個words數組,數組中每個字符串的格式為“詞性:單詞”

String[] words = {'verb:eat','verb:drink','verb:sleep','verb:play','noun:rice','noun:meat','noun:hand','noun:hair'};

根據單詞性質動詞verb全部存入verb.txt文件中

根據單詞性質名詞noun全部存入noun.txt文件中

package readandwrite;/*1.有這樣的一個words數組,數組中每個字符串的格式為“詞性:單詞” String[] words = {'verb:eat','verb:drink','verb:sleep','verb:play','noun:rice','noun:meat','noun:hand','noun:hair'}; 根據單詞性質動詞verb全部存入verb.txt文件中 根據單詞性質名詞noun全部存入noun.txt文件中*/import java.io.*;public class FileReadAndWrite { public static void main(String args[]) throws IOException { //WORDS數組 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(); }}

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持好吧啦網。

標簽: Java
相關文章:
主站蜘蛛池模板: 新巴尔虎右旗| 阿图什市| 龙游县| 卓资县| 泗阳县| 卢龙县| 樟树市| 乐东| 大庆市| 安西县| 高尔夫| 班玛县| 新平| 宣威市| 闵行区| 双桥区| 望都县| 兴业县| 大安市| 通渭县| 长泰县| 潞西市| 红原县| 镇巴县| 海兴县| 班玛县| 武川县| 禹州市| 秀山| 石景山区| 池州市| 九台市| 汉沽区| 钟山县| 龙游县| 南郑县| 敖汉旗| 德惠市| 师宗县| 库伦旗| 云安县|