标签:int exception star tst NPU fun nbsp public buffer
文件的复制方式
* 1 字节流读写单个字节
* 2 字节流读写字节数组
* 3 字节流缓冲区 读写单个字节
* 4 字节流缓冲区读写字节数组
package cn.Dong3;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
public class Copy {
public static void main(String[] args) throws Exception {
long star=System.currentTimeMillis();
fun(new File(""),new File(""));
long end=System.currentTimeMillis();
System.out.println(end-star);
}
1 字节流读写单个字节
public static void fun(File src,File desc) throws Exception
{
FileInputStream fil=new FileInputStream("f:\\qwe.txt");
FileOutputStream fos=new FileOutputStream("e:\\qwe.txt");
int l=0;
while((l=fil.read())!=-1)
{
fos.write(l);
}
fil.close();
fos.close();
}
字节流读写字节数组
public static void fun1(File src,File desc) throws Exception
{
FileInputStream fil=new FileInputStream("");
FileOutputStream fos=new FileOutputStream("");
byte b[]=new byte[1024];
int l=0;
while((l=fil.read(b))!=-1)
{
fos.write(b,0,l);
}
fil.close();
fos.close();
}
字节流缓冲区 读写单个字节
public static void fun2(File src,File desc) throws Exception
{
BufferedInputStream fil=new BufferedInputStream(new FileInputStream(""));
BufferedOutputStream fos=new BufferedOutputStream(new FileOutputStream(""));
int l=0;
while((l=fil.read())!=-1)
{
fos.write(l);
}
fil.close();
fos.close();
}
4 字节流缓冲区读写字节数组
public static void fun3(File src,File desc) throws Exception
{
BufferedInputStream fil=new BufferedInputStream(new FileInputStream(""));
BufferedOutputStream fos=new BufferedOutputStream(new FileOutputStream(""));
byte b[]=new byte[1024];
int l=0;
while((l=fil.read())!=-1)
{
fos.write(b,0,l);
}
fil.close();
fos.close();
}
}
标签:int exception star tst NPU fun nbsp public buffer
原文地址:https://www.cnblogs.com/dongzhenkun/p/10603436.html