I want to Transfer only 1/3rd of contents from one folder to other but my code is transferring all contents

I want to Transfer only 1/3rd of contents from one folder to other but my code is transferring all contents

private static void copyFilesRecursively(File src, File dest) throws IOException 
{
        if (src.isDirectory()) 
    {
            dest.mkdir();
            File[] entries = src.listFiles();
            if (entries == null) 
        {
                throw new IOException("No files in directory: " + src);
            }
            for (int i = 0; i < entries.length; i++) 
        {
                File file = entries[i];
                copyFilesRecursively(file, new File(dest, file.getName()));
            }
        } 
    else if (src.isFile()) 
    {
            try 
        {
                dest.createNewFile();
            } 
        catch (IOException ex) 
        {
                IOException ioex = new IOException("Failed creating file: " + dest);
                ioex.initCause(ex);
                throw ioex;
            }
            copy(src, dest);
        } 
    else 
    {
            System.out.println("Neither a file nor a directory");
        }
}
public static int copy(File fileIn, File fileOut) throws IOException 
{
        InputStream in = new BufferedInputStream(new FileInputStream(fileIn));
        OutputStream out = new BufferedOutputStream(new FileOutputStream(fileOut));
        try 
    {
            int byteCount = 0;
            byte[] buffer = new byte[4096];
            int bytesRead = -1;
            while ((bytesRead = in.read(buffer)) != -1) 
        {
                out.write(buffer, 0, bytesRead);
                byteCount += bytesRead;
            }
            out.flush();
            return byteCount;
        } 
        finally 
        {
            try 
            {
                in.close();
            } 
            catch (IOException ex) 
            {
            }
            try 
            {
                out.close();
            } 
            catch (IOException ex) 
            {
            }
        }
    }
View Answers

October 4, 2013 at 1:28 PM

Hi,

You may modify the code:

for (int i = 0; i < entries.length; i++)

To:

for (int i = 0; i < entries.length/3; i++)

After dividing the entries.length with 3 will copy copy the 1/3 files.

Thanks


October 7, 2013 at 11:46 PM

it is transferring only 1/3 rd of folders i want to tranfer 1/3rd of content in the subfolders.. my directory stucture is

uploaded files -sub folders -content









Related Tutorials/Questions & Answers:
I want to Transfer only 1/3rd of contents from one folder to other but my code is transferring all contents
I want to Transfer only 1/3rd of contents from one folder to other but my code is transferring all contents  private static void copyFilesRecursively...("No files in directory: " + src); } for (int i = 0; i <
Chmod 777 to a folder and all contents
Chmod 777 permission - Chmod 777 to a folder and all contents In this tutorial I am going to show you the use of the chmod command for changing the folder... of a directories.ADS_TO_REPLACE_2 How to Chmod 777 to a folder and all contents? Suppose you
Advertisements
i want to copy files from one machine to other using java and the code will be running on third machine
i want to copy files from one machine to other using java and the code will be running on third machine  i want to copy some files from one machine say 'A' to some other machine say 'B' by using the java program running on third
java program to copy the contents of one folder to another folder
java program to copy the contents of one folder to another folder  java program to copy the contents of one folder to another folder   Have a look at the following link: Java Copy one folder to another
How to copy an jpeg image from one folder to other folder using jsp
be in my image folder...so,How to copy an jpeg image from one folder to other...How to copy an jpeg image from one folder to other folder using jsp  hello, i am creating photo gallery where from admin side i allow admin to browse
I can not share my message from the textview on Facebook in Android, but in all other Application works successfully
I can not share my message from the textview on Facebook in Android, but in all other Application works successfully  TextView tv; final String str = getIntent().getExtras().getString("extra"); tv.setText(str); Intent i = new
Print Only Forms Contents - Java Beginners
Print Only Forms Contents  Hello Sir I Have Created Simple Registration Form with Database Connectivity, Now I Want To Print Registration form Contents ,How I can Do that, plz Help Me  Hi Friend, Please go through
How to copy an jpeg image from one folder to other folder using jsp
How to copy an jpeg image from one folder to other folder using jsp  How to copy an image from one folder to another folder using jsp
print only Form Fillup Contents through Text File - Java Beginners
print only Form Fillup Contents through Text File   Hello Sir ,I have Designed Employee Details Form using java swing components Now i want to print contents which is filled by employee,How i can Print it,and also i want print
This code send email two times but i want only once
This code send email two times but i want only once   public void dbbackup_notify(String email,String data,String subject){ String toEmails = email; Session session=Session.getInstance(props, new
This code send email two times but i want only once
This code send email two times but i want only once   public void dbbackup_notify(String email,String data,String subject){ String toEmails = email; Session session=Session.getInstance(props, new
i want to store dynamic number of value on one jsp and retrieve them on other.
i want to store dynamic number of value on one jsp and retrieve them on other.  in my problem, i want to run a query from database.then while in loop... the value from each drop down in a different variable. i.e i want to create as many
Code for opening a new mail from the default mail box and copy the database contents
", the code fetches the receipients, subject and the body of the mail from database, now i want a code wherein when i click on "mail" the above said data should...Code for opening a new mail from the default mail box and copy the database
I want only one method goes to sleep but both method goes to sleep together
I want only one method goes to sleep but both method goes to sleep together  I built a TicTacToe game for android. And i want that there should... want like a sleep() or any other method should be invoked between User's turn
I want only one method goes to sleep but both method goes to sleep together
I want only one method goes to sleep but both method goes to sleep together  I built a TicTacToe game for android. And i want that there should... want like a sleep() or any other method should be invoked between User's turn
i want to save image on server folder. and i want to save URL of this folder and name of image in database
i want to save image on server folder. and i want to save URL of this folder and name of image in database  hi i want to save image on server folder. and i want to save URL of this folder and name of image in database.on click
i want to create an application with only a button which on click displays table from database using struts2 and hibernate on eclipse
i want to create an application with only a button which on click displays table from database using struts2 and hibernate on eclipse  please help me i have to submit this soon
how can i define only one method from the interface. - Java Beginners
how can i define only one method from the interface.  If i am having an interface with 3 methods(declaration) . If i want to use only one method... the solution for that. please i want it immediately.  Hi friend
i want code for these programs
i want code for these programs   Advances in operating system Laboratory Work: (The following programs can be executed on any available and suitable platform) Design, develop and execute a program using any
i want to find the byte code of a image file ... for my project..plz if anybody help me for java coding i will grateful..
i want to find the byte code of a image file ... for my project..plz if anybody help me for java coding i will grateful..   i want to convert a image file to its byte code format that help me for the pattern matching in my
I have only one day to visit the Jaipur..
I have only one day to visit the Jaipur..  Hi, I have only a day to travel in Jaipur ..hence, bit worried about what to see first
Hi, I'm new to JSP I want to create 3 dropdown list each depend on the other and get the options from the database using JSP
Hi, I'm new to JSP I want to create 3 dropdown list each depend on the other and get the options from the database using JSP  as i said i want to create 3 drop dropdown list each depend on the other and get the options from
i want code of signing off from a account how its done in jsp and servlet by using either cookies or session
i want code of signing off from a account how its done in jsp and servlet by using either cookies or session   sig
Web Contents
, audio and videos and other digital assets come under web contents. A website can... Web Contents       If coding is the body of the website, web contents are the soul. Without web
i want to create an icon on my desktop... with this i want to open my web application
i want to create an icon on my desktop... with this i want to open my web application  i want to create an icon on my desktop... with this i want to open my web application(automatically run my server... )how
i want code of signing off from a account how its done in jsp and servlet by using either cookies or session
i want code of signing off from a account how its done in jsp and servlet by using either cookies or session   sig   Hi Friend, Please visit the following link:ADS_TO_REPLACE_1 http://roseindia.net/jsp/bank.shtml
ModuleNotFoundError: No module named 'contents'
ModuleNotFoundError: No module named 'contents'  Hi, My Python... 'contents' How to remove the ModuleNotFoundError: No module named 'contents... to install padas library. You can install contents python with following
ModuleNotFoundError: No module named 'contents'
ModuleNotFoundError: No module named 'contents'  Hi, My Python... 'contents' How to remove the ModuleNotFoundError: No module named 'contents... to install padas library. You can install contents python with following
I want to know the all possible syntax for EL code to print the first element of an array.
I want to know the all possible syntax for EL code to print the first element of an array.  Which is the correct EL codes syntax to print the first element of an array named employeeArray. ${employeeArray["0"]} or ${employeeArray
Moving file or directory from one directory to another
Moving file or directory from one directory to another... directory is moved from one directory to another directory. This program... from one directory to another. In this section an example is given
Read the file Contents
me,654,Cow Read file contents and Print the no.of words and Numbers./p> Thanks, Dinesh Ram   The given code read the file content and print...[]=s.split(" "); int word=0,num=0; for(int i=0;i<array.length;i
same thing i want but from db..
same thing i want but from db..  http://www.roseindia.net/tutorial/javascript/dynamicCombo.html same thing i want but from db
I want code below mention programe
I want code below mention programe  Create a web application using any technology that accepts a keyword and displays 10 relevant tweets from Twitter in real-time for that keyword
I want to learn Hadoop from scratch
I want to learn Hadoop from scratch  Hi, I want to learn Hadoop from... for companies. Now I want to learn Hadoop including all the technologies of it. How... and learn it to master all the components. I have provided you the best links to get
I want to learn Hadoop from scratch
I want to learn Hadoop from scratch  Hi, I want to learn Hadoop from... for companies. Now I want to learn Hadoop including all the technologies of it. How... and learn it to master all the components. I have provided you the best links to get
Manipulation of war fie contents
Manipulation of war fie contents  How can I manipulate a specific file inside my war file without extracting it? Please help... Thanks and regards, Swapnil
Show mu;tiple DIV contents in a page
Show mu;tiple DIV contents in a page  Hi All; I want to show...).style.display = ''; this.currvisible = show; } Now i added one... contains 5 text boxes, 6th div tag contains 6 text boxes, when i chose one
i want immediate code - Development process
i want immediate code  Basic sales tax is applicable at a rate of 10% on all goods, except books, food, and medical products that are exempt. Import duty is an additional sales tax applicable on all imported goods at a rate
ModuleNotFoundError: No module named 'consul-contents'
ModuleNotFoundError: No module named 'consul-contents'  Hi, My... named 'consul-contents' How to remove the ModuleNotFoundError: No module named 'consul-contents' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'consul-contents'
ModuleNotFoundError: No module named 'consul-contents'  Hi, My... named 'consul-contents' How to remove the ModuleNotFoundError: No module named 'consul-contents' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'github-contents'
ModuleNotFoundError: No module named 'github-contents'  Hi, My... named 'github-contents' How to remove the ModuleNotFoundError: No module named 'github-contents' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'consul-contents'
ModuleNotFoundError: No module named 'consul-contents'  Hi, My... named 'consul-contents' How to remove the ModuleNotFoundError: No module named 'consul-contents' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'github-contents'
ModuleNotFoundError: No module named 'github-contents'  Hi, My... named 'github-contents' How to remove the ModuleNotFoundError: No module named 'github-contents' error? Thanks   Hi, In your python
i have one txt field and one button.when i entere any test in testfield then only button should be enabled. i need for this
i have one txt field and one button.when i entere any test in testfield then only button should be enabled. i need for this   i have one txt field and one button.when i entere any test in testfield then only button should
i have one txt field and one button.when i entere any test in testfield then only button should be enabled.
i have one txt field and one button.when i entere any test in testfield then only button should be enabled.  i have one txt field and one button.when i entere any test in testfield then only button should be enabled. i need
I am from .net background, I want to learn SOA.
I am from .net background, I want to learn SOA.  Hi I am from .net background, I want to learn SOA. Could it possible for me to learn SOA, I suppose SOA includes Java. I dont have knowledge of java. Please help Thanks  
PHP list contents of directory
Contents of a directory or a folder can be displayed one by one. readdir() function returns the directory as well as file name. readdir() takes input as opendir() handle.On success returns the String Example of PHP List
retrieve message contents - Java Beginners
content code: display data Display Record From Database...retrieve message contents   hi , dbfile system to store message headsers in mysql database and message contents in file system . how
How do Unzip a directory and all its contents using ZipEntry class in java.
How do Unzip a directory and all its contents using ZipEntry class in java.... code import java.io.*; import java.util.*; import ... directory : data/ Name of Extract directory : data/New Folder/ Name
copy file from folder to folder - Java Beginners
copy file from folder to folder   my requirement is I need to copy xml files from one folder to another my source file contains the field filename wich contains the file to be copied. I want to copy the file from

Ads