sample..
............
input file:
input1.txt
Ram is a good boy
input2.txt
He is Very poor
output file:
output.txt
Ram is a good boy
He is very poor
CombineTwoFile.java
............
input file:
input1.txt
Ram is a good boy
input2.txt
He is Very poor
output file:
output.txt
Ram is a good boy
He is very poor
CombineTwoFile.java
package com.test;
import
java.io.BufferedReader;
import
java.io.BufferedWriter;
import
java.io.FileReader;
import
java.io.FileWriter;
import
java.io.IOException;
import
java.util.ArrayList;
public class CombineTwoFile
{
public static void main(String[]
args) throws IOException
{
ArrayList<String> list = new
ArrayList<String>();
try
{
BufferedReader br = new BufferedReader(new FileReader( "input1.txt"));
BufferedReader r = new BufferedReader(new FileReader( "input2.txt"));
String s1 =null;
String s2 = null;
while ((s1 =
br.readLine()) != null)
{
list.add(s1);
}
while((s2 =
r.readLine()) != null)
{
list.add(s2);
}
}
catch (IOException e)
{
e.printStackTrace();
}
BufferedWriter writer=null;
writer = new BufferedWriter(new FileWriter("output.txt"));
String listWord;
for (int i = 0; i<
list.size(); i++)
{
listWord = list.get(i);
writer.write(listWord);
writer.write("\n");
}
System.out.println("complited");
writer.close();
}
}
where s d coding for d package com.test???/
ReplyDeletethis program is written in eclipse, so "com" is a folder and inside 'com' folder "test" is a sub-folder....
Delete