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)      3 years and 6 months 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










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
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
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 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
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
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
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 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
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
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... writes an array of bytes onto the associated stream. code.../ Name of Extract directory : data/New Folder/ Name of Extract fille
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
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
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
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
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
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
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
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
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
Tutorials   
Java Spring Hibernate Struts Training Retrieve database from the table dynamically in jsp from oracle using servlet What does core Java include? java What are some way to learn Java quickly? Is it required to learn Java before learning Java Script? Is it necessary to learn java script before learning PHP? Are HTML5 and Java Script boosts Java career? Is Java object oriented? Fingerprint application with Java Uninstall Oracle Virtual Box JSON to HashMap Free Java online Training I want example of Control Statement in Java ANSI Color Codes with Python Create a Program that Calculates Input What is difference between JDK,JRE and JVM? How to see ubuntu version on server? How to get Page Source in Selenium (WebDriver) using Java? The path to the driver executable must be set by the webdriver.gecko.driver system property parse data from a link in java Java Program Qns using BlueJ How to fix HAX Kernel Module Is Not Installed error? Installing Audacity Looking for code Logic to check track changes & Coments in MSWord, MSWordx, MSExcel, MSExcelx is ON/OFF Installing JDK on Mac SAX Parser exception ERROR 601 (42P00): Syntax error. Encountered Thread java.lang.NoClassDefFoundError: org/apache/commons/fileupload/FileItemFactory How to install Ubuntu 16.04 LTS? HttpServletRequest cannot be resolved to a type in eclipse - Solved Unhandled event loop exception GC overhead limit exceeded Spring Data jpa with apache phoenix Caused by: java.lang.IllegalArgumentException: Not a host:port pair: PBUF o.a.h.h.z.RecoverableZooKeeper - Possibly transient ZooKeeper, quorum= com.thinkaurelius.titan.diskstorage.hbase.HBaseStoreManager class not found com.thinkaurelius.titan.diskstorage.hbase.HBaseStoreManager not found How to download and install Java 8 on Windows? How to uninstall JDK 7? How to install gtk-doc-tools package in Ubuntu? How to install Oracle JDK 8 on Ubuntu? ejabberd_ctl.beam not found - Solved How to convert date to UTC format in Java? How to install autoconf, automake and libtool in Ubuntu 15.10? How to convert current date to mm dd yyyy format in Java? How to convert current date to dd mm yyyy format in Java? How to stop window closing in "internalFrameClosing" event. How to find list of all index in Neo4j? neo4j-server.properties file location SASLError using PLAIN: not-authorized

Ads

 
Advertisement null

Ads