Results 1 to 3 of 3
- 04-24-2008, 09:29 PM #1
Member
- Join Date
- Aug 2007
- Posts
- 20
- Rep Power
- 0
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)
andJava Code:jbtUpdate.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e){ try{ long currentPosition = raf.getFilePointer(); UpdateAddress(currentPosition); } catch (IOException ex) { ex.printStackTrace(); } } }); /** Update a record at the specified position **/ public void UpdateAddress(long position){ try{ raf.seek(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){ ex.printStackTrace(); } }
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 09:55 PM.
- 04-24-2008, 09:43 PM #2
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 @ [www.littletutorials.com]
Language is froth on the surface of thought
- 04-24-2008, 10:07 PM #3
Member
- Join Date
- Aug 2007
- Posts
- 20
- Rep Power
- 0
Similar Threads
-
File Access Through Servlets
By bipinkrishna15 in forum Java ServletReplies: 1Last Post: 05-27-2008, 10:58 AM -
how to access shared file/folder in LAN
By ksheetiz in forum NetworkingReplies: 1Last Post: 05-24-2008, 04:54 AM -
Random Access Files concept
By AralX in forum New To JavaReplies: 2Last Post: 12-25-2007, 07:04 PM -
variable access from another file
By riadmazloum in forum AWT / SwingReplies: 1Last Post: 08-06-2007, 07:13 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks