reading multiple files from a directory and writing them into a single file

reading multiple files from a directory and writing them into a single file

i have done the following code but the every time i write to the single file i get an empty text file can you guide me how to do this:

/*this program reads multiple files 
 * from a single directory. */
package elite.tech.com;

import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.Reader;
import java.io.Writer;

public class reader {

    static String inpath = "C:\\Users\\ndayala\\asc";
    static String outpath = "C:\\Users\\ndayala\\bin\\bin.txt";

    public static void main(String[]args) throws IOException{
        File Folder = new File(inpath);
        File files[];
        files = Folder.listFiles();




        if(files.length>1)
        {
            for(int i = 0;i<files.length; i++){
                System.out.println("reading...");
                System.out.println(files[i]);
                Reader in = new FileReader(files[i]);
                Writer out = new FileWriter(outpath , false); 

                // should be in finally block
                in.close();
                out.close(); 
            }
        }
        else{
            System.out.println("found only one file...");
            System.out.println(files);
        }


    }

}
View Answers

January 9, 2012 at 12:32 PM


January 9, 2012 at 12:59 PM

thank you so much got it









Related Tutorials/Questions & Answers:
reading multiple files from a directory and writing them into a single file
reading multiple files from a directory and writing them into a single file... this: /*this program reads multiple files * from a single directory. */ package elite.tech.com... File(inpath); File files[]; files = Folder.listFiles
java program to read multiple files from a directory and display them on a jframe
java program to read multiple files from a directory and display them on a jframe  hi guys i want to write a java program that will read all files in a directory and display them one by on on a jframe on jpanel with specific key
Advertisements
Writing to and reading from a binary file in java.
Writing to and reading from a binary file in java.  I have written... the binary file from another program as follows: m_dis = new DataInputStream... work, but the records obtained after reading the binary file are much less than
Reading multiple xml files
Reading multiple xml files  How can we read many xml files from a folder? The same procedure as that of "listfiles
Reading and Writing files - Java Beginners
from a file. After welcoming the users, ask them for their name and save...Reading and Writing files  Hello, please help me to Develop a simple... to investigate writing to files a little (can be also done using Properties
Reading and writting multiple files
Reading and writting multiple files  how can i read and write say two different files at the same time using threads
Writing and Reading A File
Writing and Reading A File  Hello, I've been trying to learn writing and reading data from file for our assignment, but just stuck on how to proceed...;To extract the data from text file and save it to jtable, visit the following links
how to read 100 text files from a folder or directory and write the data into a single file.using java programming?
the files and write them into a single file..the target file should have the 1st...how to read 100 text files from a folder or directory and write the data into a single file.using java programming?  i have multiple(app..100) text
Writing a Program to calculate Circumference of planets reading from a file and writing to new file.
Writing a Program to calculate Circumference of planets reading from a file and writing to new file.  Hello, I would like to know how to write... stumped when it comes to reading the file and writing to a new file. My code
Writing a Program to calculate Circumference of planets reading from a file and writing to new file.
Writing a Program to calculate Circumference of planets reading from a file and writing to new file.  Hello, I would like to know how to write... it comes to reading the file and writing to a new file. My code is as follows
find jar file name from multiple set of jar files
find jar file name from multiple set of jar files   I would like to find jar file name from multiple set of jar files where the given class nameââ?¬Â?com.rational.ft.util.debugââ?¬Â
Combining records from two or more orders files into a single ordered file is called
Combining records from two or more orders files into a single ordered file is called  Combining records from two or more orders files into a single ordered file is called? 1. Menu 2. Merging 3. Taking 4. All of the above 5
help me plz:-Merge multiple jasper files into Single one
help me plz:-Merge multiple jasper files into Single one  how to Merge multiple jasper files into Single one word doc
Reading a file from Jar JAVA
Reading a file from Jar JAVA  I have added one excel sheet into a jar file. can anybody tell me how i can read that file. actually when i am running code from eclipse i able to read it but when i am adding that jar file
Reading a file from Jar JAVA
Reading a file from Jar JAVA  I have added one excel sheet into a jar file. can anybody tell me how i can read that file. actually when i am running code from eclipse i able to read it but when i am adding that jar file
Reading string from file timed
Reading string from file timed  So I want to make a file reader/ buffered reader that reads a new line of the textfile, lets say every 30 second. Like it reads the first line, waiting 30 seconds, read the next line and so one
Source file upload by attaching multiple files
Source file upload by attaching multiple files  Hi, I am trying to develop a file upload with multiple files attached functionality in java(like in gmail or in picasa). The source I found so far will select a single file. When I
Source file upload by attaching multiple files
Source file upload by attaching multiple files  Thanks for the answer. The answer posted in this link I want to have a single text box and when i... a provision to attach multiple images/files like in gmail. Is there any solution
reading dropdown values from properties file in jsp
reading dropdown values from properties file in jsp  reading dropdown values from properties file in jsp
Reading text from image file - Java Beginners
Reading text from image file  How Read text from image file
reading a csv file from a particular row
reading a csv file from a particular row  how to read a csv file from a particular row and storing data to sql server by using jsp servlet
retrieve multiple columns values from multiple csv files in java
retrieve multiple columns values from multiple csv files in java  Suppose there is folder in C:\fileupload which contains these two csv files...)///// here VendorID is corresponding to file1.csv i want to retrive data from
Copy multiple files
. For copping the data of multiple file, you need all files in a specified directory where the contents of all files are to be copied to a specified file. ...; In this section, you will learn how the data of multiple files
initialise array by reading from file - Java Beginners
initialise array by reading from file  Hello, I wnat to know how i would initialise an array by reading a text file, which contains a simple pattern. for example the file may look as shown below, with the star character
reading data from excel file and plotting graph
reading data from excel file and plotting graph  I am doing a project using NetBeans in which i have to take input an excel file and then using... at the same time from one excel file using different columns..how can i do that? waiting
Reading from remote files using PHP,Ubuntu and Windows machine.
Reading from remote files using PHP,Ubuntu and Windows machine.  Hi... on a windows machine within the same network. After reading from it, the script.... I have a php question. Am working on a script that is suppose to read from
jar file not reading input from serial port
jar file not reading input from serial port  i used a coding for getting data from serial port. JOptionbox with "port not found" message is shown when i execute thru jar file. but when i execute thru netbeans, data is received
jar file not reading input from serial port
jar file not reading input from serial port  i used a coding for getting data from serial port. JOptionbox with "port not found" message is shown when i execute thru jar file. but when i execute thru netbeans, data is received
How to move a file from a directory to other directory
How to move a file from a directory to other directory  I tried the above example it will move the folder to other directory but it does not move the image file or other file to a specified directory. Can anyone help me? Thanks
Writing and reading from/to a serialized file through Hash Table in Java
Writing and reading from/to a serialized file through Hash Table in Java... illustrates you how to read and write from/to a serialized file through the hash table.... Following program has the facility if the specified serialized file does not exist
display multiple image file or pdf file in multiple column of a row from server or database
display multiple image file or pdf file in multiple column of a row from server... in a particular format i.e I have to display more than one files in multiple columns in a single row..Suppose I have to display two files in a row then after
multiple submits, single form.
multiple submits, single form.  is it possible to use multiple submit buttons in a single form?   Thank you
how to upload multiple files in jsp and saving the path in database and the file in folder
how to upload multiple files in jsp and saving the path in database and the file in folder  how to upload multiple files in jsp and saving the path in database and the file in folder I have created a form for the upload of files
File copy from one directory to another in java
File copy from one directory to another in java  I am trying to find very good code example for copying a file from one directory to another...? Is there any size issue while copying the file from one directory to another
Reading duplicate keys from .properties file - Development process
Reading duplicate keys from .properties file  Hi, I am reading a .properties file using a basic java program.Though the .properties file will not allow duplicate keys, but still I want to develope a program to identify
Writing for the Purpose of Reading
Writing for the Purpose of Reading   ... of such an operation can vary from browser to browser. - The texts should be organized... disoriented. - The advantage of web writing is that a greater number of lists
Reading files in Java
Reading files in Java  I have to make a program in my project.... Please provide me the example code for reading big text file in Java. What do you suggest for Reading files in Java? Thanks
Moving file or directory from one directory to another
Moving file or directory from one directory to another... used for copying files from the source directory to the destination... directory is moved from one directory to another directory. This program
Java error reading from file
Java error reading from file       Java error reading file... reading from file. For this we have a class error reading from file. Inside
importing excel file and drawing multiple graphs from one excel file
importing excel file and drawing multiple graphs from one excel file  thanks a lot sir for replying with code for importing excel file... time from one excel file using different columns..and instead of passing column
Create text file at client's directory from server.
Create text file at client's directory from server.  Need java code to create text file at client's directory from server..... Please Help
Reading a text file in java
in java.io.* package for reading and writing to a file in Java. To learn more about reading text file in Java see the tutorial Read File in Java. Thanks...Reading a text file in java  What is the code for Reading a text file
reading the records from a .xlsx file and storing those records in database table
reading the records from a .xlsx file and storing those records in database table  Here is my requirement, I want to read the records from a .xlsx file and store that records in database table. I tried like this public class
Thread for reading txt file
Thread for reading txt file  how to use 3 thread to read 3 txt file? To create three threads for reading the file and three threads for getting the strings out of the queue and printing them. thanks
How to load file from the directory in J2ME?
How to load file from the directory in J2ME?  Video player J2ME. I have a folder name "music". I want to display all file with extension is "*.mpg" on the List. How can I do it, plz help me
accessing data from a json file writing javascript or using jQuery
accessing data from a json file writing javascript or using jQuery  I am trying to create a page from json objects using javascript. I have... page is built from this json file, but I can't figure out how to code
Reading XML from a File
Reading XML from a File       This Example shows you how to Load Properties from the XML file via... to create new DOM parsers. Some of the methods used for reading XML from
Reading the data from property file from java stand alone application in linux
Reading the data from property file from java stand alone application in linux  Please send me the example of reading the data from a property file from java stand alone application in linux. I don't know how to give path
How to create a new text file that contains the file names of the copied files in a new directory? - Java Beginners
file that contains the file names of the copied files in a new directory? Right now I have working code that copies multiple files and I need to create a new...How to create a new text file that contains the file names of the copied files
retrieve multiple valuesfrom a single field
retrieve multiple valuesfrom a single field  hi i am doing the project bus route network. i have fields source, destination and stages. for example...,s.perumbudur,poonamalle in a single record. i want to take the values from the stages field

Ads