package com.qf.bg;
import java.io.*;
public class Question2 {
public static void main(String[] args) throws IOException {
File file = new File("d:/jad.txt");
FileInputStream fis = new FileInputStream(file);
BufferedInputStream bis = new BufferedInputStream(fis);
File file1=new File("d:/java/2.txt ");
FileOutputStream fos=new FileOutputStream(file1);
BufferedOutputStream bos=new BufferedOutputStream(fos);
byte[] w=new byte[1024];//如果缓冲值小于文件字节数,可能会出乱码
int length;
while ((length= bis.read(w))!=-1) {
for (int i = 0; i <10 ; i++) {
bos.write(w,0,w.length);
}
}
fis.close();
bis.close();
bos.close();
fos.close();
}
}
也可以这样写
package com.qf.bg;
import java.io.*;
public class Question2 {
public static void main(String[] args) throws IOException {
BufferedInputStream bis = new BufferedInputStream(new FileInputStream(new File("d:/jad.txt")));
BufferedOutputStream bos=new BufferedOutputStream(new FileOutputStream(new File("d:/java/2.txt ")));
byte[] w=new byte[1024];//如果缓冲值小于文件字节数,可能会出乱码
int length;
while ((length= bis.read(w))!=-1) {
for (int i = 0; i <10 ; i++) {
bos.write(w,0,w.length);
}
}
bis.close();
bos.close();
}
}