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

 
 


alain ndayishimiye
reading multiple files from a directory and writing them into a single file
2 Answer(s)      a year and 4 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);
        }


    }

}
View Answers

January 9, 2012 at 12:32 PM



January 9, 2012 at 12:59 PM


thank you so much got it









Related Pages:
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
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
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
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 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
Uploading Multiple Files Using Jsp
a file. In this example we are going to tell you how we can upload multiple files... Uploading Multiple Files Using Jsp  ... to understand how you can upload multiple files by using the Jsp. We should avoid
Java read multiple files
Java read multiple files In this section you will learn how to read the data of multiple files. Here we have created four files that includes information.... We have to find the students according to particular school from all the files
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
Adding .txt files in a given directory
files from a given directory and extract tag value from body tag and add each tag value as one .txt file in a given directory? I have extracted tag values but plz help me how can I save each body tag as one .txt file and add in a directory
files
files  Question:How to create a new text file in another directory... will be created in the same directory from where the program is being runned...but how to create a new file in some other directory
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
Java count files in a directory
only files in a directory. You have learnt various file operations. Here we are going to find out the number of files from a directory. You can see... the File object to return an array of files and directory available in the given
Reading Files and Print - Java Beginners
Reading Files and Print  Hey Guys, I'm a beginner to java and I wanna write this program. I wanna create files including information of the students in my class. Each file contains a student's name, e-mail, school, hobby
Upload and Download multiple files
Upload and Download multiple files  Hello Sir/Madam, I need a simple code for upload and download multiple files(it may be image,doc and txt)which has to be store in database and also retrieve the file from database
files
and ObjectOutputStream classes to read and write from the file â??obj.txtâ??. Create variables and initialize them with the values to be written to the file. Once it is written, use ObjectInputStream to read those values from the 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
files
and ObjectOutputStream classes to read and write from the file �obj.txt�. Create variables and initialize them with the values to be written to the file. Once it is written, use ObjectInputStream to read those values from
File Directory Merging
File Directory Merging  Two directories are given. Both contain a large amount of files. Each of the directory can be more than a GB. We need to form a new directory in which all the files from both the directories
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ââ?¬Â
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
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
File I/O - Text Files
file reading and writing. // Author: Fred Swartz // Date : February 2006... from files: binary, Java objects, text, zipped files, etc. One of the most common problems is reading lines of text. Example: Copy one file to another
Display list of files from a directory using Java
Display list of files from a directory using Java In this section, you will learn how to display the list of files of a particular directory or a sub...() method display the list of file names of that directory and if it is having any
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
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
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 file and storing in map
Reading Text file and storing in map  Hi I have multiple text files. I want to read thoses files and store those records in map. Map will be of "LinkedHashMap<String, Map<String, String>>" type. Please let me know
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
Java SDK Directory Structure
;    This section introduces the Directory and file structure... stored in 'c' directory that has multiple subdirectories like bin, demo... and it's supported files. Docs directory - It is the last directory of Software
Web Writing
; The art of writing for the web is far removed from writing for the print world... content. - Reading speed from the computer screen is 25% less than the paper... from other magazines and link them to your source. Since web content is more
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
java multiple users with single connection - JSP-Servlet
java multiple users with single connection  hi, my problem... it for multiple users who uses a single connection to the database simultaneously... of the above websites uses a single connection with multiple users. n
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
Writing Hibernate Configuration Files
Writing Hibernate Configuration Files In the previous section we completed... hibernate.cfg.xml file in the source directory e.g. "C:\Struts-Hibernate.... In this section we will write required hibernate configuration files
Writing Hibernate Configuration Files
Writing Hibernate Configuration Files   ... need following Hibernate configuration files: Hibernate Configuration File...; Place hibernate.cfg.xml file in the source directory e.g. "C:\Struts
Uploading the multiple files
the three files. Copy the file from the source to destination to where to be uploaded...Multiple File uploading This script uploads the multiple file at a time. For uploading the multiple files at a time, first create a table as per required
send multiple textbox vaues in to an jsp form to store them in a DB table
send multiple textbox vaues in to an jsp form to store them in a DB table  Hi sir... I am not getting how can i send the multiple input text box values in to an jsp file with additional values to store those values
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 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
Uploading Single File by Using JSP
Uploading Single File by Using JSP  ... a file. In this example we are going to tell you how we can upload a single file... name and writing the content in new file. For this we will make a object
how to read the values for text and csv files and store those values into database in multiple rows..means one value for one row
or .txt) file and get the values from that file and store them into database table in multiple rows(which means one value for one row). eg: my file containes...")){ // creating a new file with the same name and writing the content
Chapter 6. Assemble enterprise applications and deploy them in IBM WebSphere Application Server
to load classes and JAR files from an enterprise application. WebSphere... by multiple applications (SINGLE) or unique for each application (MULTIPLE... are not isolated. When set to MULTIPLE, applications are isolated from each other
Applet Write Files Example
that allowed the permissions to the user for writing or reading the file from... the permission for writing a file from an applet. For this, you will have to maintain... helps you in writing the content in a file from an applet. First of all
Directories and Files
Java NotesDirectories and Files Put all source files into a directory, one class per file When you start a new project, create a new directory for the source files. The directory name should be lowercase letters, with no blanks
Java file
and perform various operations like renaming, deleting, reading from and writing... to the files. The File class in "java.io" package works with files and directories and it's object represents the name of a file or directory on the host file
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

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.