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
Ads
Related Tutorials/Questions & Answers:
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
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
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 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
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
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
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