try (BufferedInputStream bis = new BufferedInputStream(
new FileInputStream(file));
BufferedOutputStream bos = new BufferedOutputStream(
new FileOutputStream(file2));
) {
int len;
while ((len = bis.read()) != -1) {
bos.write(len);
}
}
}
private static File getFile() {
// 创建键盘录入文件夹路径,并判断是否为文件夹,
Scanner sc = new Scanner(System.in);
while (true) {
System.out.println("请输入文件夹位置:");
String s = sc.nextLine();
File file = new File(s);
if (!file.exists()) {
System.out.println("目录不存在!请重新输入");
} else if (file.isFile()) {
System.out.println("这是一个文件,请输入一个文件夹目录");
} else {
return file;
}
try (BufferedInputStream bis = new BufferedInputStream(
new FileInputStream(file));
BufferedOutputStream bos = new BufferedOutputStream(
new FileOutputStream(file2));
) {
int len;
while ((len = bis.read()) != -1) {
bos.write(len);
}
}
}
private static File getFile() {
// 创建键盘录入文件夹路径,并判断是否为文件夹,
Scanner sc = new Scanner(System.in);
while (true) {
System.out.println("请输入文件夹位置:");
String s = sc.nextLine();
File file = new File(s);
if (!file.exists()) {
System.out.println("目录不存在!请重新输入");
} else if (file.isFile()) {
System.out.println("这是一个文件,请输入一个文件夹目录");
} else {
return file;
}