• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Add a RecordNumber field

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 245
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
If you like strawberry rhubarb pie, try blueberry rhubarb (bluebarb) pie. And try this tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic