IO流

  1. 文件输出流的应用。
    定义如下字符串:
    String str = “12345abcdef@#%&*软件工程”;
    编写程序将该字符串写入文件”data.txt”。
  2. 文件输入流的应用。
    修改第1题中的程序,读文件”data.txt”,将读到的数据输出在控制台。
  3. 谈一谈本次实训的体会。
    import java.io.*;
    
    public class IO {
        public static void main(String[] args) throws IOException{
            String str="12345abcde@#%&*软件工程";
            File file=new File("d:\\tset.txt");
            file.createNewFile();
            FileInputStream fr=new FileInputStream(file);
            FileOutputStream fw=new FileOutputStream(file);
            byte[]bw=str.getBytes();
            fw.write(bw);
            byte[]br=str.getBytes();
            fr.read(br);
            String str$=new String(br);
            System.out.println(str$);
            fr.close();
            fw.close();
        }
    }

     

posted @ 2019-07-05 11:16  ShijouTakane  阅读(80)  评论(0编辑  收藏  举报