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

Ads
 

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

Ads









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 <
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
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
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
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
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
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
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 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
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
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 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
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
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 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
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
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 '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 '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 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
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
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
Storage medium that loses its contents
Storage medium that loses its contents  A Storage medium that loses its contents in the events of power failure is called? 1. Volatile storage 2. Non volatile storage 3. Permanent storage 4. All of the above 5. None

Ads