package com.cebbank.doa.test;
import java.io.*;
public class IOCopy {
public static void main(String[] args){
IOCopy copy = new IOCopy();
// copy.copyByByte1();
copy.copyByByte2(); //推荐这个 速度快
// copy.copyByByte3();
}
public void copyByByte1(){
try{
FileInputStream fis = new FileInputStream("d:/11.xls");
FileOutputStream fos = new FileOutputStream("d:/22.xls");
int b = fis.read();
while(b != -1){
fos.write(b);
b = fis.read();
}
fis.close();
}catch(IOException e){
e.printStackTrace();
}
}
public void copyByByte2(){
try{
FileInputStream fis = new FileInputStream("d:/11.xls");
FileOutputStream fos = new FileOutputStream("d:/22.xls");
byte[] b = new byte[1024];
int n = fis.read(b,0,24);
while(n != -1){
fos.write(b,0,n);
n = fis.read(b,0,24);
}
fis.close();
}catch(IOException e){
e.printStackTrace();
}
}
public void copyByByte3(){
try{
FileInputStream fis = new FileInputStream("d:/11.xls");
FileOutputStream fos = new FileOutputStream("d:/22.xls");
byte[] b = new byte[1024];
int n = fis.read(b,100,20);
while(n != -1){
fos.write(b,100,n);
n = fis.read(b,100,20);
}
fis.close();
}catch(IOException e){
e.printStackTrace();
}
}
public void copyByCharactor(){
try{
BufferedReader br = new BufferedReader(new FileReader("d:/11.xls"));
BufferedWriter bw = new BufferedWriter(new FileWriter("d:/22.xls"));
String line = br.readLine();
int j = 0;
while(line != null){
bw.write(line);
line = br.readLine();
if(line != null)
bw.newLine();
}
bw.close();
br.close();
}catch(IOException e){
e.printStackTrace();
}
}
public void copyByCharactor1(){
try{
BufferedReader br = new BufferedReader(new FileReader("d:/11.xls"));
PrintWriter pw = new PrintWriter(new FileWriter("d:/22.xls"));
String line = br.readLine();
while(line != null){
pw.print(line);
line = br.readLine();
if(line!=null){
pw.println();
}
}
pw.close();
br.close();
}catch(IOException e){
e.printStackTrace();
}
}
}
10-17
10-17