Random Access help please

How do you create a method which allows you to enter information for example on a employee, then add more records using random access file.. i'm looking for this everywhere, but i can't find a command line interface which does this..
THanks

a file is not a good idea; Use a relational database instead (MySQL for example).
here is a sample code to use random access file:
try {
        File f = new File("filename");
        RandomAccessFile raf = new RandomAccessFile(f, "rw");
        // Read a character
        char ch = raf.readChar();
        // Seek to end of file
        raf.seek(f.length());
        // Append to the end
        raf.writeChars("aString");
        raf.close();
    } catch (IOException e) {
    }

Similar Messages

  • Generating rectangles in random points with a random sizes. help please =)

    i want this to generate a lot of random rectangles in random points with different sizes all at once.
    so far i have this but it only generates one. it seems to me like it should do a lot but it doesnt. please help =)
    import javax.swing.*;
    import java.awt.*;
    import java.util.*;
    public class randomSquares{
      public static void main(String[] args) {
        randomSquares d = new randomSquares();
      public randomSquares(){
        JFrame frame = new JFrame();
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.getContentPane().add(new MyComponent());
        frame.setSize(500,500);
        frame.setVisible(true); 
      public class MyComponent extends JComponent{
        public void paint(Graphics g){
          int height = 500;
          int width = 500;
         Random r = new Random();
         int number = r.nextInt();
         int random_number = number % 500; {
         if (random_number < 1) random_number = random_number + 500;
         System.out.println(random_number);
         for (int i = 0; i < 500; i++);{
              g.drawRect(random_number, random_number, random_number, random_number);
    }Edited by: javanub123 on Nov 13, 2009 7:27 PM

    javanub123 wrote:
    public class MyComponent extends JComponent{
    public void paint(Graphics g){Swing components should not override paint(Graphics) but instead paintComponent(Graphics).
    int height = 500;
    int width = 500;
         Random r = new Random();And a Random object should probably not be instantiated during either of those methods. It would be better to declare it as a class attribute and instantiate the Random object at time of construction.
    The Random class produces a series of numbers that is 'seeded' using the current time. If called in quick succession, it might produce identical series of numbers.
    Also, please use a single upper case letter at the start of each sentence. This helps the reader to quickly scan the text, looking for ways to help. You would not want to make it harder for someone to help, would you?

  • LoadMovieNum fails on firefox (randomly) -- urgent help, please

    i have a loader movie that has the following frames:
    it works just fine on my computer and in internet explorer,
    but would fail loading swf to level 1 on firefox.
    please suggest.
    thank you

    Your post kind of helped me. Thank you. I have modified the
    script as follows:
    The idea behind this is that, usualy, if I check
    _level1.getTotalBytes()... it would return undefined until I get
    nuts... It seems that if I try to load the swf few times... it
    succedes--eventually.
    I had this problem in Fireworks. IE works fine. Haven't
    checked any other broswer.
    ;)

  • Airport Extreme - Remote is not passing internet access - help please

    I have the following:
    Cable modem - > WAN of Airport Extreme. - works perfectly - wireless clients in range get internet access and the network works.
    Second Airpot Extreme set to relay this network. It connects, gets a "green" light - seems to be set up properly, but wireless clients in that area cannot get internet. Why is it not passing internet.
    Can anyone explain step by step how to do this or post a link to an apple doc?
    Thank you,
    Miklos.

    Hi, actually this is still not working.
    I got the second base station configured so that when it started up, it was working properly as a "remote" station, and I was getting internet fine through an ibook there (which is normally too far away from the main station to get any signal).
    However, today, although the second "remote" station still has a green light and is connected to the network it is not getting an IP address from the main base station - and so I can't get any internet through that 2nd base station anymore.
    Why was it working yesterday and not today when I've changed nothing?
    Any help much appreciatd.
    Miklos.

  • Please Come IN! IanSchneider. About random access serialized objects.

    Hi,I'm a freshman.
    I have a question about serialized objects.
    If I useing writeObject() serialize objects into a file in order,I can gain them with readObject() in the same order. But if I want to random access these serialized objects rather than one by one,how to do?
    Mr IanSchneider said "write all your objects into the same file using normal io techniques and you can still generate an index and acheive random access". It seems easy,but how to generate index and use it to acheive random access? Please write something in detail,Thank you in advance!
    EXPECTING��

    Have a look at this class: [ [u]WARNING: I just wrote this code, it hasn't been tested ]
    import java.io.BufferedInputStream;
    import java.io.ByteArrayInputStream;
    import java.io.ByteArrayOutputStream;
    import java.io.File;
    import java.io.FileNotFoundException;
    import java.io.IOException;
    import java.io.ObjectInputStream;
    import java.io.ObjectOutputStream;
    import java.io.RandomAccessFile;
    import java.io.Serializable;
    import java.util.ArrayList;
    public class SerializedObjectWriter {
         private RandomAccessFile raf;
         private String filepath;
         private String mode;
         public SerializedObjectWriter(String filePath, String mode) throws FileNotFoundException {                         
              this.filepath = filePath;
              this.mode = mode;
              this.raf = new RandomAccessFile(filePath, mode);                         
         public void writeObject(Object o, long pos) throws IOException {
              raf.seek(pos);          
              final byte[] bytes = serialize((Serializable)o);     
              raf.writeInt(bytes.length);     
              raf.write(bytes);
         public void append(Object o) throws IOException {                    
              writeObject(o, raf.length());
         public Object readObject(long pos) throws IOException, ClassNotFoundException {
              raf.seek(pos);
              int len = raf.readInt();          
              final byte[] data = new byte[len];          
              raf.readFully(data);
              return deSerialize(data);
         public Object[] readAllObjects() throws IOException, ClassNotFoundException {          
              int pos = 0;          
              final ArrayList al = new ArrayList();
              while (true) {
                   raf.seek(pos);
                   final int len = raf.readInt();               
                   final byte[] data = new byte[len];          
                   raf.readFully(data);
                   al.add(deSerialize(data));
                   pos = (pos + len + 4);               
                   if (pos >= raf.length()) break;               
              return al.toArray();
         public long length() throws IOException {
              return raf.length();
         public void reset() throws IOException {          
              raf.close();
              final boolean success = new File(filepath).delete();
              if (!success) throw new IOException("Failed to delete file");
              raf = new RandomAccessFile(filepath, mode);
         public void close() throws IOException {          
              raf.close();     
         private byte[] serialize(Serializable obj) throws IOException {
              final ByteArrayOutputStream baos = new ByteArrayOutputStream();
              final ObjectOutputStream oos = new ObjectOutputStream(baos);
              try {
                   oos.writeObject(obj);
              } finally {
                   oos.close();
              return baos.toByteArray();
         private Object deSerialize(byte[] data) throws IOException, ClassNotFoundException {
              final ByteArrayInputStream bais = new ByteArrayInputStream(data);     
              final BufferedInputStream bis = new BufferedInputStream(bais);
              final ObjectInputStream ois = new ObjectInputStream(bis);
              try {
                   return (Serializable) ois.readObject();               
              } finally {
                   ois.close();
         public static void main(String[] args) throws Exception {
              SerializedObjectWriter sor = new SerializedObjectWriter("C:\\test.ser", "rw");          
              sor.reset();
              sor.writeObject("Test 1", 0);                         
              sor.append("Test 2");               
              sor.append("Test 3");     
              Object[] objects = sor.readAllObjects();
              for (int i = 0; i < objects.length; i++) {
                   System.out.println(objects);
              sor.close();

  • My iPhone gone mad can't turn off voice control which turned on by itself now can't access phone as can't get past my screen lock! Also it keeps calling random people in my contacts help please

    iPhone 4 gone mad voice control taken over phone, can't get past my screen lock it won't  respond at all, keeps dialling random people won't do anything at all!!! Even when go on voice control screen and hold power off and home screen down nothing No response. Help please? My mother very sick in hospital and need my mobile!!

    Have you tried to power off and on?  If that doesn't work and the reset didn't work, have you tried connecting to iTunes to see if it is recognized?
    If none of this works you probably need to visit an Apple genius bar and have it checked out by the techs.

  • I have downloaded several books into ibooks.  Started reading one and closed it when I was done reading for the day.  Now I want to access other books and when I open ibooks it goes directly to that first book.  What can I do? Help please.

    I have downloaded several books into ibooks.  Started reading one and closed it when I was done reading for the day.  Now I want to access other books and when I open ibooks it goes directly to that first book.  It does not give me the shelf to choose what book I want to read - goes directly to the first book. What can I do? Help please.

    There should be a Library button on the top left. If not ap the middle of the screen to get it to appear.

  • I can no longer access Safari on my ipad. I get the error:the operation couldn't be completed. Cannot allocate memory. Help please!

    I am not able to access Safari on my ipad. I get the error message: The operation couldn't be completed. Cannot allocate memory. Can anyone help please??

    Try this first.
    Go to Settings>Safari>Clear History, Cookies and Data. Restart the iPad. Restart the iPad by holding down on the sleep button until the red slider appears and then slide to shut off. To power up hold the sleep button until the Apple logo appears and let go of the button.
    If that doesn't work, reboot the iPad - or quit all apps and restart.
    Reboot the iPad by holding down on the sleep and home buttons at the same time for about 10-15 seconds until the Apple Logo appears - ignore the red slider - let go of the buttons.
    Quit all apps completely and restart the iPad. Go to the home screen first by tapping the home button. Double tap the home button and the task bar will appear with all of your recent/open apps displayed at the bottom. Tap and hold down on any app icon until it begins to wiggle. Tap the minus sign in the upper left corner of the app that you want to close. Tap the home button or anywhere above the task bar. Restart the iPad.

  • I can no longer access Bejeweled Blitz through my facebook account.  I get the message that says, "your browser sent a request that this server could not understand. Size of a request header field exceeds server limit".  Help please.

    I can no longer access Bejeweled Blitz through facebook.  I get the message, "your browser sent a request that this server could not understand. Size of a request header field exceeds server limit". I can access Bejeweled through FB using my husband's log in so to me that suggests the problem is with my log in. Help please.

    Contact FB or use another browser. 

  • After hours of back-up, downloading and uploading...I am now updated with all the latest Mac software. However, I no longer have access to Excel and Word. Is there a way I can access my documents in either of those? Help, please.

    After hours of back-up, downloading and uploading...I am now updated with all the latest Mac software. However, I no longer have access to Excel and Word. Is there a way I can access my documents in either of those? Help, please.

    If you have older versions of excel and word that previously ran under the Rosetta emulator (allows PowerPC code to run on Intel system), they will no longer work with Lion.
    You can use the Apple programs Pages and Numbers to access the files. They can be bought and downloaded from the App store. NeoOffice is available at http://www.neooffice.org/neojava/en/index.php which has Lion support. OpenOffice doesn't talk to Lion support, it's at http://www.openoffice.org/

  • I can't access my kindle app on my iPad even though I am wifi connected and receiving emails.  I am visiting France, but it has worked here before.  Help, please!

    I can't access my kindle app on my iPad even though I am wifi connected.  Am visiting in France right now but was able to get in yesterday and can't today. Help, please.

    What operating system does your iMac have? (please always post your operating system to prevent confustion).
    If it's pre-Lion you will have to set Mail up manually:
    Entering iCloud email settings manually in Snow Leopard or Leopard
    Entering iCloud email settings manually in Tiger

  • HT204053 I cannot access iCloud when I get to put in my password I am told there is no verification and to go to my mail for verification but when I go there I have nothing,help please.

    I am trying to access iCloud,I have had my ipad for over a year and did not use it,but now I have my I phone5 I find I can't do a lot with them together,so looking into this more I think it may be an iCloud issue,when I try to sign in I am told my account needs a verification or something??and to go to my mail which I do but nothing there,can I sestet  and start again as my ignorance of these matters at the start may be causing this,help please.

    Make sure you are checking the email address you used to set up your iCloud account.  Check the spam/junk folder as well as the inbox.  If it isn't there, go to https://appleid.apple.com, click Manage your Apple ID, sign in, click on Name, ID and Email addresses on the left, then to the right click Resend under your Primary Email Address to resend the verification email.

  • Hi, I am trying to convert my resume on pages to a word document.  When i export the file to to make it a word document ie(resume.doc) it messes up my whole resume on websites and pulls up a bunch of random words. Please help!

    Hi, I am trying to convert my resume on pages to a word document.  When i export the file to to make it a word document ie(resume.doc) it messes up my whole resume on websites and pulls up a bunch of random words. Please help!

    What exactly is the problem?
    Your description is so muddled I am having trouble working it out.
    How does your exported .doc file mess up websites? In fact what does it have to do with websites?
    Where, how and what are the random words turning up?
    Peter

  • My time machine cannot complete my back up saying the "sparse bundle could not be accessed" error -1  Help please

    My time machine cannot complete my back up.  The message I receive says the "sparse bundle cannot be accessed.  (error -1)  Help please.

    GG,
    Please read over Pondini's Time Machine Troubleshooting guide, specifically C17.

  • My 'old' files have been backed up onto time capsule (Leopard), I have upgraded to Lion (thro snow leopard) and now checking back to retosre some old files i can't see or access beyond the date I upgraded to Lion? Help please?

    My 'old' files have been backed up onto time capsule (Leopard), I have upgraded to Lion (thro snow leopard) and now checking back to retosre some old files i can't see or access beyond the date I upgraded to Lion? Help please?

    Use the manual methods.. but it is possible for TM to wipe the old files in trying to fit into the space.
    Try Q16.. but read all the section 14-17
    http://pondini.org/TM/FAQ.html

Maybe you are looking for

  • How do I find old forgotten apple id's

    Here's a question and a story......Once upon a time in a land far far away......okay it's not really a fairy tale so seriously ....I have had my iPod Classic for ever and a day, love it, it goes with me every where BUT it is registered to an old Appl

  • Not able to create plnd order in prod view

    Hi, When I try to create an order using product view, it gives me an error message, 'Invalid product-location combination (pegging area), A product-location combination exists in the APO database but not in liveCache' Can someone help me with getting

  • [MOOT] Can't access bootloader in laptop w/out chainloading (syslinux)

    EDIT: Laptop died shortly into thread. I've run into a curious error as I'm installing onto a new laptop for the wife (Acer Aspire V5-531).  As in most laptops, it has a single hard drive. I've gone through the install, and threw on syslinux as the b

  • SAML AS JAVA user mapping. Can table VUSREXTID On AS ABAP be leveraged?

    The documentation on the SAML AS java user mapping refers to Mapping SAML Principals to SAP J2EE Engine User IDs - User Authentication and Single Sign-On - SAP Library custom development. In my case the users are managed on the AS ABAP system. Can I

  • DBMS export extension

    Does anyone know what the DBMS export extension is in the quote from the following article: "... revoke public execute permissions for DBMS export extension ..." http://news.com.com/Patched+Oracle+database+still+at+risk%2C+bughunter+says/2100-1002_3-