• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Add a RecordNumber field

 
Philip Hong
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I try to add a Record Number field to "db.db" by using following code:
String oldFileName = "db.db";
String newFileName = "fbndb.db";
int recordNumber = 1;
String recordField = "Record Number";

DataInputStream in = new DataInputStream(new
FileInputStream(oldFileName));
DataOutputStream out = new DataOutputStream(new
FileOutputStream(newFileName));

String textLine = "";
textLine = in.readLine();
textLine = recordField + " " + textLine;
//System.out.println(textLine);
out.writeChars(textLine);

textLine = in.readLine();
while(textLine!=null){
textLine = recordNumber + " " + textLine;
//System.out.println(textLine);
out.writeChars(textLine);

recordNumber+= 1;
textLine = in.readLine();
}

The code simply adds Record Number field and RecordNumber to "db.db", but when I type the fbndb.db, the file format has been changed.
Any help really appreciated
 
davidlong
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
The problem was that you used the readLine() method, the db.db do not hava line format at all.
check the Data class second constructor to see how it does for creating a new database file, refer that to create your own.
David
 
Paul Smiley
Ranch Hand
Posts: 245
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Unless you have a different project than I, I don't think you need to add a record number field - there is one implicitly in the binary file.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic