JAVA文件读写例题实现过程解析
练习
有这样的一个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文件中
packagereadandwrite;
/*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文件中
*/
importjava.io.*;
publicclassFileReadAndWrite{
publicstaticvoidmain(Stringargs[])throwsIOException{
//WORDS数组
String[]words={"verb:eat","verb:drink","verb:sleep","verb:play","noun:rice","noun:meat","noun:hand","noun:hair"};
FileOutputStreamoutFile1=newFileOutputStream("verb.txt");
FileOutputStreamoutFile2=newFileOutputStream("noun.txt");
OutputStreamout1=newBufferedOutputStream(outFile1);
OutputStreamout2=newBufferedOutputStream(outFile2);
for(inti=0;i
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持毛票票。