import java.io.*;
import java.util.*;
class CopyFile {
public static void main(String args[]) throws IOException {
FileInputStream in = null;
FileOutputStream out= null;
try {
in= new FileInputStream(args[0]);
out= new FileOutputStream(args[1]);
/*if(out.exists()){
System.out.println("File Already exists");
}*/
File f= new File (args[1]);
if(f.exists() && !f.isDirectory()) {
System.out.println("File exists Do you want to override");
Scanner sca=new Scanner(System.in);
System.out.println("enter Y/N");
char ch=sca.next().charAt(0);
if (ch=='y' || ch=='Y') {
int c;
while ((c= in.read())!=-1) {
out.write(c);
}
System.out.println("FIle Copied Succesfully");
}
else {
System.out.println("File not copied");
}
}
}
catch (FileNotFoundException e) {
System.out.println("File Not exists");
}
finally {
if (in!=null) {
in.close();
}
if(out!=null) {
out.close();
}
}
}
}
import java.util.*;
class CopyFile {
public static void main(String args[]) throws IOException {
FileInputStream in = null;
FileOutputStream out= null;
try {
in= new FileInputStream(args[0]);
out= new FileOutputStream(args[1]);
/*if(out.exists()){
System.out.println("File Already exists");
}*/
File f= new File (args[1]);
if(f.exists() && !f.isDirectory()) {
System.out.println("File exists Do you want to override");
Scanner sca=new Scanner(System.in);
System.out.println("enter Y/N");
char ch=sca.next().charAt(0);
if (ch=='y' || ch=='Y') {
int c;
while ((c= in.read())!=-1) {
out.write(c);
}
System.out.println("FIle Copied Succesfully");
}
else {
System.out.println("File not copied");
}
}
}
catch (FileNotFoundException e) {
System.out.println("File Not exists");
}
finally {
if (in!=null) {
in.close();
}
if(out!=null) {
out.close();
}
}
}
}
0 Comments