• 编写IoDemo.java的Java应用程序,程序完成的功能是:首先读取text.txt文件内容,再通过键盘输入文件的名称为iodemo.txt,把text.txt的内容存入iodemo.txt


    package com.hanqi.io;
    
    import java.io.*;
    
    
    public class IoDemo {
    
        public static void main(String[] args) {
            try 
            {
                File file=new File("d:/testRW.txt");
                if(!file.exists())
                {            
                file.createNewFile();
                 }
                
            
             FileReader    fr = new FileReader(file);
            
             String str="";
             char[] a=new char[1024];
             int i=0;
             while((i=fr.read(a))>0)
             {
                 str+=new String(a,0,i);
             }
             
             fr.close();
             System.out.println("d:/testRW.txt");
             System.out.println(str);
            
            File file2=new File("d:/iodemo.txt");
            if(!file2.exists())
            {            
               file2.createNewFile();
            }
            FileWriter fw=new FileWriter(file2);
             fw.write(str);
             fw.close();
    
             FileReader    fr2 = new FileReader(file2);
            
             String str2="";
             char[] a2=new char[1024];
             int j=0;
             while((j=fr2.read(a2))>0)
             {
                 str2+=new String(a2,0,j);
             }
             
             fr2.close();
             System.out.println("d:/iodemo.txt");
             System.out.println(str2);
            }
            catch (Exception e) {
                // TODO 自动生成的 catch 块
                e.printStackTrace();
            }
        }
    
    }

  • 相关阅读:
    tyvj1034 尼克的任务
    一维数状数组区间修改,查询
    ACM-T3分块
    测试2T3
    IOS下自定义click事件使用alert的bug
    小知识点
    CSS3动画基本知识
    CSS3秘笈:第十二章&第十三章
    CSS3秘笈:第十一章
    CSS3秘笈:第十章
  • 原文地址:https://www.cnblogs.com/wenwen123/p/5546196.html
Copyright © 2020-2023  润新知