首页 > 其他 > 详细

复制文件到另外一个地址

时间:2019-11-03 21:08:15      阅读:86      评论:0      收藏:0      [点我收藏+]
/*
第一种复制每次复制一个字符
*/

package test;


import java.io.FileReader;
import java.io.FileWriter;
import java.math.BigDecimal;
import java.nio.channels.NonReadableChannelException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.*;

public class Main {

	private static final String space_operator = " ";
	private static final double pi = Math.PI;
	private static final String LINE_SEPARATOR = System.getProperty("line.separator");
	public static void main(String[] args) throws Exception {

		FileReader fReader = new FileReader("e:\\开开.txt");
		FileWriter fWriter = new FileWriter("copy_2.txt");
		
		int ch = 0;
		while((ch = fReader.read()) != -1)
		{
			fWriter.write(ch);
		}
		fReader.close();
		fWriter.close();
	
	}
}


/*
第二种方法用数组复制
*/

package test;


import java.io.FileReader;
import java.io.FileWriter;
import java.math.BigDecimal;
import java.nio.channels.NonReadableChannelException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.*;

public class Main {

	private static final String space_operator = " ";
	private static final double pi = Math.PI;
	private static final String LINE_SEPARATOR = System.getProperty("line.separator");
	public static void main(String[] args) throws Exception {

		FileReader fReader = new FileReader("e:\\开开.txt");
		FileWriter fWriter = new FileWriter("copy_3.txt");
		
		char []buf = new char[1024];
		int len = 0;
		while((len = fReader.read(buf)) != -1)
		{
			fWriter.write(new String(buf,0,len));
		}
		fReader.close();
		fWriter.close();
	
	}
}

  

复制文件到另外一个地址

原文:https://www.cnblogs.com/WINDZLY/p/11788765.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!