my intention is to read name ,age and address from 3 different files and write this as a single record to a output file.Don't know how can i give a newline break between two records.I tried but not getting proper result
//This program will read name,age and address from name.txt,age.txt,address.txt respectively
//and write them in finals.txt
import java.io.*;
class RandAccess
{
public static void main(
String[] args)
{
try
{
File file = new File("name.txt");
RandomAccessFile raf_name = new RandomAccessFile(file, "r");
File file1 = new File("age.txt");
RandomAccessFile raf_age = new RandomAccessFile(file1, "r");
File file2 = new File("address.txt");
RandomAccessFile raf_add = new RandomAccessFile(file2, "r");
File file3 = new File("finals.txt");
RandomAccessFile raf_finals = new RandomAccessFile(file3, "rw");
String read_str; //will be used to store read string from various files
char c;
while ((read_str = raf_name.readLine()) != null)
// while (raf_name.length())
{
raf_finals.writeChars("name--");
raf_finals.writeBytes(read_str);
raf_finals.write(0x0A);
raf_finals.writeBytes("\n");
read_str = raf_age.readLine();
raf_finals.writeChars("age--");
raf_finals.writeChars(read_str); //write age
raf_finals.writeChars("address--");
while ((c = raf_add.readChar()) != ';') //read chracter untill ";" is found
{
raf_finals.writeChar(c); //write address
}
raf_finals.writeBytes("\n");
//pr.println("\n"); //used to give a line break between different records
//pr.println("<<<<>>>>>"); //marks the end of record
//raf_finals.seek(file.length());
}
raf_name.close();
raf_age.close();
raf_add.close();
raf_finals.close();
}
catch (Exception e){}
}
}