package com.heima.io;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Scanner;
public class D08_ {
/**
* @param args控制台输入一个路径 考皮到当前目录下
* @throws InterruptedException
* @throws IOException
*/
public static void main(String[] args) throws IOException, InterruptedException {
File file= getfile();
BufferedInputStream bis = new BufferedInputStream
(new FileInputStream("file));
BufferedOutputStream bos = new BufferedOutputStream
(new FileOutputStream("copy.jpg"));
int len;
while ((len=bis.read())!=-1){
bos.wait(len);
}
bis.close();
bos.close();
}
public static File getfile() {
Scanner sc= new Scanner(System.in);
System.out.println("输入路径");
while(true){
String line = sc.nextLine();
File file = new File(line); //封装成file对象 可以用file的方法
if(!file.exists()){
System.out.println("录入路径不存在 请重新录入");
}else if(file.isDirectory()){
System.out.println("录入的是 文件夹 从新录入 ");
}else{
return file ;
}
}
}
}
|
|