package com.heima.test;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Scanner;
public class Test1 {
public static void main(String[] args) throws IOException {
File file=getFile();
BufferedInputStream bis=new BufferedInputStream(new FileInputStream(file));
BufferedOutputStream bos=new BufferedOutputStream(new FileOutputStream(file.getName()));//获取文件名称
int b;
while((b=bis.read())!=-1) {
bos.write(b);
}
bis.close();
bos.close();
}
public static File getFile() {
Scanner sc=new Scanner(System.in);
while(true) {
String line=sc.nextLine();
File file=new File(line);
if(file.exists()) {
System.out.println("该文件不存在");
}else if(file.isDirectory()) {
System.out.println("录入的是目录,请重新录入");
}else {
return file;
}
}
}
}