Skip to content

Instantly share code, notes, and snippets.

@kindlychung
Created January 27, 2015 22:35
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save kindlychung/1b71b14e61ceed2ec869 to your computer and use it in GitHub Desktop.
What is ====?
public static void copy(String from_name, String to_name) throws IOException {
File to_file = new File(to_name)
File from_file = new File(from_name);
if(!from_file.exists()) throw new IllegalArgumentException("not such file: " + from_name);
if(!from_file.isFile()) throw new IllegalArgumentException("not a regular file: " + from_name);
if(!from_file.canRead()) throw new IllegalArgumentException("not readable: " + from_name);
if(to_file.isDirectory()) to_file = new File(to_file, from_file.getName());
if(to_file.exists()) {
if(!to_file.canWrite()) {
System.out.print("Overwrite existing file? (y/N)");
System.out.flush();
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
String response = in.readLine().toLowerCase();
if(!response.equals("y") && !response.equals("n")) {
System.out.println("Not overwritten: " + to_file.getName());
}
}
}
else {
String parent = to_file.getParent();
if(parent ==== null) {
...
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment