Results 1 to 3 of 3
  1. #1
    AralX is offline Member
    Join Date
    Dec 2007
    Location
    KSA, Riyadh
    Posts
    9
    Rep Power
    0

    Default Random Access Files

    Hey 'all !
    ******************************************
    -------------------updated---------------------------------
    - what is below the Update blockis answered-
    ~New -go to postNumber 3 , there is myQuestion-
    ******************************************
    how is everyone ?

    I want to get to under stand the concept .. of Random access files

    now , that I have a file and and initialized an Object of a RandomAccessFile class .. in the form of "rw" (Read/write) ...here i can write and read randomly .. but can I Edit randomly .. like delet a file then replace it with a new data ?

    thanks :)
    Last edited by AralX; 12-25-2007 at 08:08 PM. Reason: Updating

  2. #2
    hardwired's Avatar
    hardwired is offline Senior Member
    Join Date
    Jul 2007
    Posts
    1,576
    Rep Power
    9

    Default

    but can I Edit randomly .. like delet a file then replace it with a new data ?
    Yes. The RandomAccessFile class api has methods for navigating within the raf, reading and writing. You also have String methods available. Here's an older article about RandomAccessFiles: JDC Tech Tips: May 09, 2000.

  3. #3
    AralX is offline Member
    Join Date
    Dec 2007
    Location
    KSA, Riyadh
    Posts
    9
    Rep Power
    0

    Default

    I don't want to Open a new thread , so I'd reather post my Question here aslong as it is related ..

    when reading from a RAF .i found this exception

    Java Code:
    at java.io.RandomAccessFile.readInt(Unknown Source)
    	at HardwareRecord.readRecord(HardwareRecord.java:81)
    	at HardwareStoreInventory.getRecordFileandCheck(HardwareStoreInventory.java:33)
    	at HardwareStoreInventory.AddFile(HardwareStoreInventory.java:12)
    	at testerProg.RunOption(testerProg.java:66)
    	at testerProg.RunApplication(testerProg.java:18)
    	at Application.main(Application.java:19)
    the line 81 is

    Java Code:
    	setRecordnumber(datafile.readInt());
    		setToolName(StringModifierReader(datafile));
    		setQuantity(datafile.readInt());
    		setCost(datafile.readDouble());
    and from a website it says that this Kind of exception when Occures with readInt() of the RAF
    is usuallu because that it reached the eand of the file before 4 Bytes .. or something like that

    but I have calculated the File length correctly
    4 Bytes(Int)* 2(I have two)= 8
    8Bytes(Double)*1 = 8 +
    30Bytes(String of 15Chars)=30+
    -------------------------------------------
    the Total is 46
    which will be the size of each file right ?

    what do you people suggest me to do in order to handle the Exception ?

    Thanks again :)
    has been solved just now incase you are woundering... the file was Empty, thats why :D

    thanks everyone
    Last edited by AralX; 12-25-2007 at 10:18 PM.

Similar Threads

  1. mail concept
    By indirani in forum New To Java
    Replies: 3
    Last Post: 04-16-2008, 02:30 PM
  2. random numbers without random class`
    By carlos123 in forum New To Java
    Replies: 4
    Last Post: 01-17-2008, 11:44 PM
  3. Replies: 1
    Last Post: 08-07-2007, 08:51 AM
  4. access to dll files
    By Heather in forum Advanced Java
    Replies: 1
    Last Post: 07-08-2007, 01:30 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •