一聚教程网:一个值得你收藏的教程网站

最新下载

热门教程

JAVA文件读写例题如何实现 JAVA文件读写例题实现过程代码解析

时间:2020-06-29 编辑:袖梨 来源:一聚教程网

本篇文章小编给大家分享一下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数组
    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
                

热门栏目