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



Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


Geeta
FileHandling
1 Answer(s)      5 years and 4 months ago
Posted in : Java Beginners



Advertisement
View Answers

September 3, 2009 at 4:18 PM


Hi Friend,

Try the following code:

import java.io.*;
import java.util.Scanner;

class FileConcat {

public static void main (String args []) throws IOException {
Scanner stdin = new Scanner (System.in);
System.out.print ("Enter two text file name with path: ");
String filename1 = stdin.next();
String filename2 = stdin.next();

File file=new File (filename1);
FileInputStream fstream = new FileInputStream(file);
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String strLine;
while ((strLine = br.readLine()) != null) {
FileWriter fostream = new FileWriter("Master.txt",true);
BufferedWriter output = new BufferedWriter(fostream);
output.write(strLine);
output.newLine();
output.close();
}

File file1=new File (filename2);
FileInputStream fstream1 = new FileInputStream(file1);
DataInputStream in1 = new DataInputStream(fstream1);
BufferedReader br1 = new BufferedReader(new InputStreamReader(in1));
String strLine1;

while ((strLine1 = br1.readLine()) != null) {
FileWriter fostream1 = new FileWriter("Master.txt",true);
BufferedWriter output1 = new BufferedWriter(fostream1);
output1.write(strLine1);
output1.newLine();
output1.close();
}
}
}

Thanks


Related Tutorials/Questions & Answers:
FileHandling - Java Beginners
FileHandling  Q. Write a java prg which accepts a list of existing text files from command line args & concatinate contents of all files in the "Master.txt". I have tried to solve it but with errors. Kindly ammend the existing
PHP realpath() function and example
C:\xampp\htdocs\filehandling\aa.txt
Advertisements
PHP dirname() Function, PHP dirname(), dirname php
;); echo $dir2; ?> Output c:/xampp/htdocs/filehandling c:/xampp/htdocs
Create File in Java
of how to create a file in java: package FileHandling; import java.io.File
fileoutputstream example
package FileHandling; import java.io.FileOutputStream; import
Java search text file
message. Example: import java.io.*; import java.util.*; class FileHandling
Java Error - Java Beginners
Java Error  E:\SUSHANT\Core Java\FileHandling\Error>javac demo1.java demo1.java:15: possible loss of precision found : int required: char...); //System.out.println("Enter characters, 'q' to quit."); try
Java read file
line. Example of Java Read File: package FileHandling; import
 

 

 

DMCA.com