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



Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


Mehmet Tahir KAVAK
Read Write
1 Answer(s)      3 years and 10 months ago
Posted in : Java Beginners


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


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


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
read and write a file using javascript
read and write a file using javascript  How to read and write a file using javascript
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
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
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 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
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
read paragraph
read paragraph  how to read paragraph from one file to another file
Read bufferedreader
Read bufferedreader  Tell me the example of Read file using bufferedreader. Thanks   Read the tutorial Reading file using BufferedReader class. Thanks
xl read
xl read  hi, i have read excel sheet data using poi api and printed on console, now i have to store the same data which is printed on the console...: Insert excel file data into database Read Excel File
read a file
read a file  read a file byte by byte   import java.io.File; import java.io.FileInputStream; public class ReadFileByteArray { public static void main(String[] args) { File file = new File("D://Try.txt"); try
Write String in Word document
Write String in Word document  How to read and write strings in word document
read image
read image  java code to read an image in the form of an array.   import java.io.*; import javax.imageio.*; import java.awt.image.*; class ReadImageInArray { public static int[] getImagePixels(BufferedImage image
read xml
read xml   hi all, i want to ask about how to read an xml in java ME.. here is the xml file <data> <value> <struct> <member> <name> User_Name
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
 

 

 

DMCA.com