文件之间的拷贝

来源:互联网 发布:方维o2o源码下载 编辑:程序博客网 时间:2024/05/02 05:57
package org.file.test;

import java.io.*;

class FileInOut
{
    
public static void main(String args[]) throws Exception
    {
        System.out.println(
"从键盘输入文件内容,以回车结束:");
        
char c;
        StringBuffer buf
=new StringBuffer();
        
try
        {
            
while((c=(char)System.in.read())!=' ')
            buf.append(c);
        }
        
catch(java.io.IOException e)
        {
            e.printStackTrace();
        }
        
        
byte b[]=buf.toString().trim().getBytes();
        FileOutputStream f1
=new FileOutputStream("file1.txt");
        f1.write(b);
        f1.close();
        
        FileInputStream f2
=new FileInputStream("file1.txt");
        FileOutputStream f3
=new FileOutputStream("file2.txt");
        
int c2;
        
while((c2=f2.read())!=-1)
        {
            f3.write(c2);
        }
        f2.close();
        f3.close();
    }
}
 
原创粉丝点击