import java.io.*;
// the purpose this api is to combine content of two input stream file together
public class SequenceInputStreamEx {
public static void main(String[] args) throws Exception {
FileOutputStream file1 = new FileOutputStream("F:\\file1.txt");
FileOutputStream file2 = new FileOutputStream("F:\\file2.txt");
String s1 = "He is awaken";
byte b[]= s1.getBytes();
file1.write(b);
String s2 = "He will conquer all";
byte c[]=s2.getBytes();
file2.write(c);
file1.close();
file2.close();
// will put the above data in two files respectively
*********************************************************************************
// will combine the two file data , here we display in console and write in file also.
public static void main(String[] args) throws Exception {
FileInputStream file1 = new FileInputStream("F:\\file1.txt");
FileInputStream file2 = new FileInputStream("F:\\file2.txt");
FileOutputStream fout = new FileOutputStream("F:\\SeqFile.txt");
SequenceInputStream seqFile = new SequenceInputStream(file1, file2); // the two file data are combined together
int i;
while((i=seqFile.read())!=-1)
{
fout.write(i); //writting the combined data in differnt file
System.out.print((char)i);
}
}
}
output
He is awakenHe will conquer all
// the purpose this api is to combine content of two input stream file together
public class SequenceInputStreamEx {
public static void main(String[] args) throws Exception {
FileOutputStream file1 = new FileOutputStream("F:\\file1.txt");
FileOutputStream file2 = new FileOutputStream("F:\\file2.txt");
String s1 = "He is awaken";
byte b[]= s1.getBytes();
file1.write(b);
String s2 = "He will conquer all";
byte c[]=s2.getBytes();
file2.write(c);
file1.close();
file2.close();
// will put the above data in two files respectively
*********************************************************************************
// will combine the two file data , here we display in console and write in file also.
public static void main(String[] args) throws Exception {
FileInputStream file1 = new FileInputStream("F:\\file1.txt");
FileInputStream file2 = new FileInputStream("F:\\file2.txt");
FileOutputStream fout = new FileOutputStream("F:\\SeqFile.txt");
SequenceInputStream seqFile = new SequenceInputStream(file1, file2); // the two file data are combined together
int i;
while((i=seqFile.read())!=-1)
{
fout.write(i); //writting the combined data in differnt file
System.out.print((char)i);
}
}
}
output
He is awakenHe will conquer all
No comments:
Post a Comment