package TestingFile;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
public class Demo01 {
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
copyFile("D:\\QQ\\1.txt","E:\\");
}
public static void copyFile(String src, String des) throws IOException {
File file1 = new File(src); //源文件所在地址
File fileDir = new File(des); //目标地址
String topath = des + "\\" + file1.getName();
File file2 = new File(topath);
if(!fileDir.exists()){
fileDir.mkdirs();s
}
InputStream in = new FileInputStream(src);
FileOutputStream fs = new FileOutputStream(topath);
byte[] buffer = new byte[]{}; //创建一个接收数据的数组
int length;
int byteread=0;
int bytesum = 0;
while((byteread = in.read(buffer))!=-1){
// bytesum += byteread;
//System.out.print(bytesum);
fs.write(buffer, 0, byteread);
}
in.close();
fs.close();
System.out.println("successfully" + topath);
}
}
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
public class Demo01 {
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
copyFile("D:\\QQ\\1.txt","E:\\");
}
public static void copyFile(String src, String des) throws IOException {
File file1 = new File(src); //源文件所在地址
File fileDir = new File(des); //目标地址
String topath = des + "\\" + file1.getName();
File file2 = new File(topath);
if(!fileDir.exists()){
fileDir.mkdirs();s
}
InputStream in = new FileInputStream(src);
FileOutputStream fs = new FileOutputStream(topath);
byte[] buffer = new byte[]{}; //创建一个接收数据的数组
int length;
int byteread=0;
int bytesum = 0;
while((byteread = in.read(buffer))!=-1){
// bytesum += byteread;
//System.out.print(bytesum);
fs.write(buffer, 0, byteread);
}
in.close();
fs.close();
System.out.println("successfully" + topath);
}
}