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

Ads

 
 

Share on Google+Share on Google+

rupa anusha teegala
I want to Transfer only 1/3rd of contents from one folder to other but my code is transferring all contents
2 Answer(s)      4 years and a month ago
Posted in : Java Beginners
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) 
            {
            }
        }
    }
Ads
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
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
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 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
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 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
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
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 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
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 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 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
Moving file or directory from one directory to another
; If you want to move file or directory from other directory... Moving file or directory from one directory to another... directory is moved from one directory to another directory. This program
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
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
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
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
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
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

Ads

 
Advertisement null

Ads