zoukankan      html  css  js  c++  java
  • 编写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();
            }
        }
    
    }

  • 相关阅读:
    树四:遍历二叉树
    树三:创建二叉树
    树二:二叉树定义及性质
    树一:定义及存储
    排序七:归并排序
    排序六:快速排序
    排序五:希尔排序
    排序四:冒泡排序
    深入分析Linux内核链表
    179. Largest Number
  • 原文地址:https://www.cnblogs.com/wenwen123/p/5546196.html
Copyright © 2011-2022 走看看