import java.io.IOException;
import java.util.Scanner;
public class Demo6_File {
public static void main(String[] args) throws IOException {
//在控制台录入文件的路径,将文件拷贝到当前项目下
Scanner sc = new Scanner(System.in);
System.out.println("请输入一个文件路径");
String line = sc.nextLine(); //将键盘录入的文件路径存储在line中
File file = new File(line); //封装成File对象
FileInputStream fis = new FileInputStream(file);
FileOutputStream fos = new FileOutputStream(file.getName());
int len;
byte[] arr = new byte[8192]; //定义缓冲区
while((len = fis.read(arr)) != -1) {
fos.write(arr,0,len);
}
fis.close();
fos.close();
}
}
|
|