Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners I want to Transfer only 1/3rd of contents from one folder to other but my code is transferring all contents

Have Programming Question? Ask it here!
 
 
 


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)      10 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) 
            {
            }
        }
    }

Advertisement
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
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
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
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 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
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
Java Programming: Contents
Appendix 3: Source code for all examples in the text News and Errata... Introduction to Programming Using Java, Fourth Edition Table of Contents THIS IS THE FULL TABLE OF CONTENTS for version 4.1 of an on-line
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 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
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
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
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
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
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
PHP file_get_contents() Function
PHP file_get_contents() Function  Hi, How do i read the content of file using PHP program? So kindly provide any example or online help reference for filegetcontents() Function in PHP. Please feel free to suggest. Thanks
How to print contents of a web page in jsp?
How to print contents of a web page in jsp?  I have generated a pay slip using jsp.How do I print the contents of the slip
The PHP file_get_contents() function , file_get_contents php
PHP file_get_contents(path,[include_path,[context,[start,[max_length]]]]) Code...The PHP file_get_contents() Function Function reads the content of the whole file to a string. This function is the best way to read the contents
The PHP file_put_contents() function , file_put_contents php
_APPEND LOCK_EX Code & Example of file_put_contents() PHP <?php...; $data1="\nindia is my country"; file_put_contents("c:/rose1/ram...Learn how to use file_put_contents() function in PHP Example of the PHP
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
How to browse excel file and stored the contents into the database using jsp/servlet?
How to browse excel file and stored the contents into the database using jsp/servlet?  Hi.. I want to browse excel file and stored the file data into the My-sql database using jsp/servlet
Java read file contents into byte array
Java read file contents into byte array  Hello share the code of java read file contents into byte array with me. It's urgent. Thanks   Hi, This is simple process if you use the InputStream class. Read example
How to read excel contents when uploaded
How to read excel contents when uploaded  I am working on a project where the user uploads his excel file. Jsp page must read the excel contents and display it on the screen. I am using Apache POI for importing the jar
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: http://roseindia.net/jsp/bank.shtml Thanks
display contents on the same page by selecting a radio button
")) { %> Due Date<input type="date" name="date"/> <% } %> i want if i click on pending then the due date text field should be displayed...display contents on the same page by selecting a radio button  Bill
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
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
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
query in simple code..i had described all...........
query in simple code..i had described all...........  SAME HERE IF YOU GET THIS PROBLEM SOLVED THEN PLEASE REPLY......... MY ONE JAVA FILE...("an"); } } AND THIRD ONE IS: class AbstractDemo { public static void main(String args
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
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
Java - Copying one file to another
;    This example illustrates how to copy contents from one... the contents from one specified file to another specified file. copyfile(String...; and then create a byte type buffer for buffering the contents of one file and write
 

 

 

DMCA.com