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









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
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...: In this tutorial we have learned to read a text file and then write it to another 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 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
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 a program
write a program  write a program add 2 no.s without use arithmetic,unary operaters in java
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 ADS_TO_REPLACE_1
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 String in Word document
Write String in Word document  How to read and write strings in word document
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
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 {ADS_TO_REPLACE_1 public static void main(String[] args) { File file = new File("D
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
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
Java write to file
Java write to file  How to write to a file in Java? Is there any... files. You can easily use the the FileWriter and BufferedWriter to write data to a text file. Here is the examples: Example program to write to file. File
write a java program
write a java program  write a program to print '*' in a circular form
write data to plist
write data to plist  How to write data to plist file in XCode
Write Text File to Table
Write Text File to Table       In this section, you will learn how to read the records of a simple text file and write (insert) into a simple table in MySQL
How to write Java Program
How to write Java Program  how to write a program to find average of 5 student marks
Write data in doc file
Write data in doc file  How to write data or string in word file
How to write in File in Java
How to write in File in Java  Hi, How to write in File in Java. Please suggest and give example of this program. thanks
ModuleNotFoundError: No module named 'write'
ModuleNotFoundError: No module named 'write'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'write' How to remove the ModuleNotFoundError: No module named 'write'
ModuleNotFoundError: No module named 'write'
ModuleNotFoundError: No module named 'write'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'write' How to remove the ModuleNotFoundError: No module named 'write'
how to write in xml? - XML
how to write in xml?  can anybody give the code how to write in xml file. i wan to write inside the tag, so what i have to do? Thanks...  ...) tFormer.setOutputProperty(OutputKeys.METHOD, "text"); // Write the document to a file
write a programm using java
write a programm using java  print the following using java programming
write java prgram
write java prgram  write java program to offer a menu which contains 3 choices to make calculation on 3 shapes.use method for each calculation

Ads