java中的接口是类吗
315
2022-12-03
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文件中
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数组
qKdlsqCV 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 if(words[i].startsWith("verb")){ byte[] bytes1 = words[i].getBytes(); out1.write(bytes1); } if(words[i].startsWith("noun")){ byte[] bytes2 = words[i].getBytes(); qKdlsqCV out2.write(bytes2); } } out1.close(); out2.close(); } }
if(words[i].startsWith("verb")){
byte[] bytes1 = words[i].getBytes();
out1.write(bytes1);
}
if(words[i].startsWith("noun")){
byte[] bytes2 = words[i].getBytes();
qKdlsqCV out2.write(bytes2);
}
}
out1.close();
out2.close();
}
}
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~