Read Write

Read Write

Hi; How can I read certain line of say 10 text files and write to one text file

View Answers

February 5, 2011 at 11:10 AM

Java Read Multiple Files and store the data into another text file

The given code reads all the text files of the directory and stored the data into another text file.

import java.io.*;
import java.util.jar.*;
class OnlyExt implements FilenameFilter{
  String ext;
  public OnlyExt(String ext){
  this.ext="." + ext;
  }
  public boolean accept(File dir,String name){
  return name.endsWith(ext);
  }
}
public class ReadMultipleFiles{
public static void main(String[]args) throws Exception{
BufferedWriter bw=new BufferedWriter(new FileWriter(new File("C:/output.txt")));
FilenameFilter ff = new OnlyExt("txt");
File f=new File("C:/");
File[] files = f.listFiles(ff);
for(int i=0;i<files.length;i++){
FileReader fr = new FileReader(files[i].getPath());
            BufferedReader reader = new BufferedReader(fr);
            String st = "";
            while ((st = reader.readLine()) != null) {
            bw.write(st);
            bw.newLine();
            }
}
bw.close();
 }
}

Ads









Related Tutorials/Questions & Answers:
Read Write
Read Write  Hi; How can I read certain line of say 10 text files and write to one text file   Java Read Multiple Files and store the data into another text file The given code reads all the text files of the directory
Read and write file
Read and write file  HI, How to read and write file from Java program? Thanks   Hi, See the following tutorials: Java Write To File Read File Thanks
Advertisements
tow method to read and write .
tow method to read and write .  i have two method , frist named "readString" which has no input ,and output b type string ,. second method named "writeString" which accept b as imput and return nothing .........please i want
ModuleNotFoundError: No module named 'write-read'
ModuleNotFoundError: No module named 'write-read'  Hi, My Python... 'write-read' How to remove the ModuleNotFoundError: No module named 'write-read' error? Thanks   Hi, In your python environment you
ModuleNotFoundError: No module named 'write-read'
ModuleNotFoundError: No module named 'write-read'  Hi, My Python... 'write-read' How to remove the ModuleNotFoundError: No module named 'write-read' error? Thanks   Hi, In your python environment you
how to write and read text for javaME
how to write and read text for javaME  Hi. I have tried ur read/write coding but why i didnt get the o/p just like urs. do i have to add anything from the library? i want to type multiple line on text file then, read it from
Java file read write operation
Java file read write operation  how to read and write the data from text file.Suppose i have text file with 4 fields name ,roll no ,marks1,marks2 with more than 20 records......i need to store these value in object and pass
read/write to Windows Registry using Java
read/write to Windows Registry using Java  read/write to Windows Registry using Java
write a progam for bubble sort using file read nd write?
write a progam for bubble sort using file read nd write?  hi, please give the code
how to read and write an xml file using java
how to read and write an xml file using java  Hi Can anyone help me how to read and write an xml file which has CData using java
how to read and write xml files in javascript
how to read and write xml files in javascript  hi m very new to javascript and xml,, now i want to read and write xml files in javascript,, please give me a sample code to do
To read & write a excel file using the core java
To read & write a excel file using the core java  Hai, I'm new to JavaProgram.But now i need java program to read & write a excel file so, can anyone help me to learn the above mentioned topic(link for the portion
J2ME RMS Read Write
J2ME RMS Read Write       This Application specially tries to explain how to read and write the data using RecordStore class. In the RecordStore class the following methods
write a program in java to read a text file and write the output to an excel file using filereader and filewriter?
write a program in java to read a text file and write the output to an excel file using filereader and filewriter?  write a program in java to read a text file and write the output to an excel file using filereader and filewriter
simple code to write an read and write the login detail to a xml file using javascript ( username and password )
simple code to write an read and write the login detail to a xml file using javascript ( username and password )  pls can nyone give me a code to write and read the login details (username and password )into a xml file using
Write a C language program to read two matrices and multiply them?
Write a C language program to read two matrices and multiply them?  Write a C language program to read two matrices and multiply them?   ...;stdio.h> #include <conio.h> int main() { int m, n, p, q, c, d, k, sum
is there any possibelities fast read and write file large data file
is there any possibelities fast read and write file large data file  import java.io.BufferedReader; import java.io.BufferedWriter; import...) { //read from start original file String arry[] = sCurrentLine.split
is there any possibelities fast read and write file large data file
is there any possibelities fast read and write file large data file  import java.io.BufferedReader; import java.io.BufferedWriter; import...) { //read from start original file String arry[] = sCurrentLine.split
is there any possibelities fast read and write file large data file
is there any possibelities fast read and write file large data file  import java.io.BufferedReader; import java.io.BufferedWriter; import...) { //read from start original file String arry[] = sCurrentLine.split
Java program to read a text file and write to another file
Java program to read a text file and write to another file - Creating.... Our requirement is to read a text file and then write the content of the text... and the class is used to read data from a file. The could be text file
how to read 100 text files from a folder or directory and write the data into a single file.using java programming?
how to read 100 text files from a folder or directory and write the data... column value that keeps on changing for every file.i have read the data from all the files and write them into a single file..the target file should have the 1st
write spreadsheet
write spreadsheet  what is the java code to write a spreadsheet to database
write spreadsheet
write spreadsheet  what is the java code to write a spreadsheet to database
Write to a file
Write to a file       As we have read about  the BufferedOutputStream class that store the data in an internal buffer and lets you write
Ajax Write
Ajax Write       ajaxWrite is a web-based word processor that can read and write Microsoft Word and other standard document formats Read full Description
write a program
write a program  write a program add 2 no.s without use arithmetic,unary operaters in java
Write String in Word document
Write String in Word document  How to read and write strings in word document
How to Read file line by line in Java program
Programmers have always found it difficult to read a big file (5-10 GB) line by line in Java. But there are various ways that can help read a larger file... Reader and readline() method one can read the data faster even on the computer
How to read properties file in Python using configparser?
How to read properties file in Python using configparser and printing the property value? In Python we can read the configuration file and then is required.... In this tutorial we are going to make a sample property file and then read
WRITE AND TEST
WRITE AND TEST   WRITE AND TEST PROGRAM TO ACCEPT A STRING? 1).WHICH STARTS WITH 'S' OR 's' 2).ENDS WITH "nd" 3) THE LENGTH OF THE STRING SHOULD BE 10 OR LESS
Write to PDF
Write to PDF  Hi, Fairly new to this. I want to create a PDF file as a server call, with text/images sent to the app. Seeing that this will have to be a plugin, how do I go about making it a valid plugin for the server

Ads