Results 1 to 3 of 3
  1. #1
    Rgfirefly24 is offline Member
    Join Date
    Aug 2007
    Rep Power

    Default Update a record in Random access file

    I have been given a program that will add and search through records from a random access file.
    I need to add an update button so that i can change items in a record and replace the old record with the new one.

    The problem is That when i execute the program that the update doesn't happen it just places a new record behind the one i want to update. It also doesn't put in anything but the name.

    I have tried putting inputting a string with the name street city state and zip but i'm not sure how to parse it back out.

    i know that i need to do something along these lines:

    oldvariable = new name/street/city/state/zip(which ever I'm doing at the time)
    Java Code:
       jbtUpdate.addActionListener(new ActionListener() {
    		public void actionPerformed(ActionEvent e){
    				long currentPosition = raf.getFilePointer();
    			catch (IOException ex) {
      /** Update a record at the specified position **/
      public void UpdateAddress(long position){
    		  FixedLengthStringIO.UpdateFixedLengthString(jtfName.getText(), NAME_SIZE, raf);
    		  FixedLengthStringIO.UpdateFixedLengthString(jtfStreet.getText(), STREET_SIZE, raf);
    		  FixedLengthStringIO.UpdateFixedLengthString(jtfCity.getText(), CITY_SIZE, raf);
    		  FixedLengthStringIO.UpdateFixedLengthString(jtfState.getText(), STATE_SIZE, raf);
    		  FixedLengthStringIO.UpdateFixedLengthString(jtfZip.getText(), ZIP_SIZE, raf);
    	  catch(IOException ex){

    Java Code:
    public static void UpdateFixedLengthString(String s, int size, DataOutput out) throws IOException{
    	  char[] chars = new char[size];
    	  s.getChars(0, Math.min(s.length(), size), chars, 0);
    	  for (int i = Math.min(s.length(), size); i < chars.length; i++)
    	  	chars[i] = ' ';
    	  	out.writeChars(new String(chars));
    Last edited by Rgfirefly24; 04-24-2008 at 10:55 PM.

  2. #2
    danielstoner's Avatar
    danielstoner is offline Senior Member
    Join Date
    Apr 2008
    Rep Power


    Hello, just a small piece of advice because I see this kind of posts a lot. The best way to ask for help is to structure your message like this in order:

    1. Describe the problem, what you try to solve
    2. Describe the solution, your design or algorithm
    3. Describe the error/issue, what doesn't work as expected
    4. Describe what you already tried in order to solve the problem
    5. Show the code, as much as possible to be relevant, but don't flood me with thousands of irrelevant lines

    I know this requires more effort from your side but it presents clear advantages to you:
    - you actually think in a structured way about your problem and who knows you might actually solve it without any help
    - you help us to help you; if you give me 1000 LOC without any explanation probably I won't read it

    Sorry if this sounds like a rant or a flame but... this is what it is! ...eerrr, just joking, actually it is very honest advice. Take care man.
    Daniel @ []
    Language is froth on the surface of thought

  3. #3
    Rgfirefly24 is offline Member
    Join Date
    Aug 2007
    Rep Power

Similar Threads

  1. File Access Through Servlets
    By bipinkrishna15 in forum Java Servlet
    Replies: 1
    Last Post: 05-27-2008, 11:58 AM
  2. how to access shared file/folder in LAN
    By ksheetiz in forum Networking
    Replies: 1
    Last Post: 05-24-2008, 05:54 AM
  3. Random Access Files concept
    By AralX in forum New To Java
    Replies: 2
    Last Post: 12-25-2007, 08:04 PM
  4. variable access from another file
    By riadmazloum in forum AWT / Swing
    Replies: 1
    Last Post: 08-06-2007, 08:13 PM

Posting Permissions

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