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



Home Answers Viewqa Java-Beginners reading multiple files from a directory and writing them into a single file
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


alain ndayishimiye
reading multiple files from a directory and writing them into a single file
2 Answer(s)      2 years and 10 months ago
Posted in : Java Beginners


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);
        }


    }

}

Advertisement
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
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 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
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 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
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
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
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
Moving file or directory from one directory to another
Moving file or directory from one directory to another... files from the source directory to the destination directory. This method...; If you want to move file or directory from other directory
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
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
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 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
reading dropdown values from properties file in jsp
reading dropdown values from properties file in jsp  reading dropdown values from properties file in jsp
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 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
Reading text from image file - Java Beginners
Reading text from image file  How Read text from image file
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
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 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
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
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
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
Advertisements
 

 

 

DMCA.com