EzDevInfo.com

copy interview questions

Top copy frequently asked interview questions

Standard concise way to copy a file in Java?

It has always bothered me that the only way to copy a file in Java involves opening streams, declaring a buffer, reading in one file, looping through it, and writing it out to the other steam. The web is littered with similar, yet still slightly different implementations of this type of solution.

Is there a better way that stays within the bounds of the Java language (meaning does not involve exec-ing OS specific commands)? Perhaps in some reliable open source utility package, that would at least obscure this underlying implementation and provide a one line solution?


Source: (StackOverflow)

Fast way to copy dictionary in Python

I have a Python program that works with dictionaries a lot. I have to make copies of dictionaries thousands of times. I need a copy of both the keys and the associated contents. The copy will be edited and must not be linked to the original (e.g. changes in the copy must not affect the original.)

Keys are Strings, Values are Integers (0/1).

I currently use a simple way:

newDict = oldDict.copy()

Profiling my Code shows that the copy operation takes most of the time.

Are there faster alternatives to the dict.copy() method? What would be fastest?


Source: (StackOverflow)

Advertisements

Android: How to copy files from 'assets' folder to sdcard?

I have a few files in the assets folder. I need to copy all of them to a folder say /sdcard/folder. I want to do this from within a thread. How do I do it?


Source: (StackOverflow)

Copy text to clipboard with iPhone SDK

What is the best way to copy text to the iPhone's clipboard in your application?

Their docs are sketchy and have way more features than what I want... I just want to set a string as the users clipboard.


Source: (StackOverflow)

Best way to copy the entire contents of a directory in C#

I want to copy the entire contents of a directory from one location to another in C#.

There doesn't appear to be a way to do this using System.IO classes without lots of recursion.

There is a method in VB that we can use if we add a reference to Microsoft.VisualBasic:

new Microsoft.VisualBasic.Devices.Computer().
    FileSystem.CopyDirectory( sourceFolder, outputFolder );

This seems like a rather ugly hack. Is there a better way?


Source: (StackOverflow)

Copy tables from one database to another in SQL Server

I have a database called foo and a database called bar. I have a table in foo called tblFoobar that I want to move (data and all) to database bar from database foo. What is the SQL statement to do this?


Source: (StackOverflow)

How to clone or copy a list in Python?

What are the options to clone or copy a list in Python?

Using new_list = my_list then modifies new_list every time my_list changes. Why is this?


Source: (StackOverflow)

How can I create a copy of an Oracle table without copying the data?

I know the statement:

create table xyz_new as select * from xyz;

Which copies the structure and the data, but what if I just want the structure?


Source: (StackOverflow)

Make copy of array Java

I have an array A which is constantly being updated. Lets say A = [1,2,3,4,5]. I need to make an exact duplicate copy of A and call it B. If A were to change to [6,7,8,9,10], B should still be [1,2,3,4,5]. What is the best way to do this? I tried a for loop like:

for(int i=0; i<5; i++){
   B[i]=A[i]
}

but that doesn't seem to work correctly. Please don't use advanced terms like deep copy etc because I do not know what that means.


Source: (StackOverflow)

Eclipse copy/paste entire line keyboard shortcut

Anyone know the keyboard shortcut to copy/paste a line into a new line in Eclipse, without having to highlight the entire line?

ctrl-alt-down turns my whole screen upside down (I'm on windows). Interestingly, that's what's specified in the windows->preferences.


Source: (StackOverflow)

Copying files from host to docker container

I am trying to build a backup and restore solution for the docker containers that we work with.

I have docker base image that I have created ubuntu:base and do not want have to rebuild it each time with a dockerfile to add files to it.

I want to create a script that runs from the host machine and creates a new container using the ubuntu:base docker image and then copies files into that container. But I am stuck copy files on the container

How can I copy files from the host to the container?


Source: (StackOverflow)

Git: copy all files in a directory from another branch

How do I copy all files in a directory from another branch? I can list all of the files in that directory by doing

git ls-tree master:dirname

I can then copy all of the files individually by doing

git checkout master -- dirname/filename

However, using wildcards has so far been a total fail. This does nothing:

git checkout master -- dirname/*.png

Though I guess I can use a bash script to do that, there has to be an easier way, right?


Source: (StackOverflow)

How to scp a folder from remote to local?

I am not sure whether it is possible to scp a folder from remote to local, but still I am left with no other options. I use ssh to log into my server and from there I would like to copy the folder foo to home/user/Desktop (my local). Is there any command so that I can do this?


Source: (StackOverflow)

How do I copy an object in Java?

Consider the below code:

DummyBean dum = new DummyBean();
dum.setDummy("foo");
System.out.println(dum.getDummy()); // prints 'foo'

DummyBean dumtwo = dum;
System.out.println(dumtwo.getDummy()); // prints 'foo'

dum.setDummy("bar");
System.out.println(dumtwo.getDummy()); // prints 'bar' but it should print 'foo'

So, I want to copy the 'dum' to dumtwo' and I want to change 'dum' without affecting the 'dumtwo'. But the above code is not doing that. When I change something in 'dum', the same change is happening in 'dumtwo' also.

I guess, when I say dumtwo = dum, Java copies the reference only. So, is there any way to create a fresh copy of 'dum' and assign it to 'dumtwo' ?


Source: (StackOverflow)

Javascript fastest way to duplicate an Array - slice vs for loop

In order to duplicate an Array in Javascript,

does anyone know (and maybe tested) if it's faster to use:

Slice method:

var dup_array = original_array.slice();

or For loop:

for(var i = 0, len = original_array.length; i < len; ++i)
   dup_array[i] = original_array[i];

UPDATE: (just to clarify myself) I know both ways do only a shallow copy: if original_array contains references to objects, objects won't be cloned, but only the references will be copied therefore both arrays will have references to the same objects. But this is not the point of this question.

I'm asking only about speed.


Source: (StackOverflow)