Results 1 to 6 of 6
  1. #1
    ozzyman's Avatar
    ozzyman is offline Senior Member
    Join Date
    Mar 2011
    Location
    London, UK
    Posts
    797
    Blog Entries
    2
    Rep Power
    4

    Default Is there a neat way of storing program files?

    My java program is a till system, so every time a transaction is made or editted it is saved or updated to its own file. Whenever a Z report is made, before the orders are cleared the entire list of that days orders are serialised and saved to another file. So if there are 100 transactions and then a Z is made, there will be 101 files.

    I also plan on saving records for over 1 year so that the user can compare year-on-year figures, so there will be a LOT of files. Also, because the system will (in the future) require a login and password and 'manager access' to view all the sales reports, it wouldn't be ideal to leave the order files in sight of 'everyone' and allow 'everyone' to edit/delete/corrupt those files.

    I was hoping that by creating a blank resource package I could store the files in the resource package (within the JAR file) until it is deleted by the 'manager' or by a set age of the file. But now I don't think that is so possible, so can anyone tell me the best way of doing this please?

    Java Code:
    public class IOWrite {
    
        public static void writeNewOrders(java.util.List<Order> orderList) {
            String filename = "/ozzypos/z/" + Date.getFormattedDate(true) + ".pos";
            FileOutputStream fos = null;
            ObjectOutputStream out = null;
            try {
                fos = new FileOutputStream(filename);
                out = new ObjectOutputStream(fos);
                out.writeObject(orderList);
                out.close();
            } catch (IOException ex) {
                ex.printStackTrace();
            }
        }

    In the above code, if i remove the "ozzypos/z/" from the path string the files are saved in the same folder as the executable JAR file. However, now it wont work because ozzypos/z/ folders don't exist, but I didn't want to create folders... I wanted to save to the package called 'ozzypos.z'

  2. #2
    gedas is offline Member
    Join Date
    Feb 2010
    Posts
    51
    Rep Power
    0

    Default

    why dont you try using a mysql database its neat and very easy to use. you could do all the things you have specified above.

  3. #3
    ozzyman's Avatar
    ozzyman is offline Senior Member
    Join Date
    Mar 2011
    Location
    London, UK
    Posts
    797
    Blog Entries
    2
    Rep Power
    4

    Default

    ahh a database..... i was hoping to avoid databases but looks like it may be inevitable now.

    so instead of storing files, i would have to create new records into the database, but then... will the database be able to "hold" or store my data Objects directly? or will i need to run loops to fill in each record?

  4. #4
    gedas is offline Member
    Join Date
    Feb 2010
    Posts
    51
    Rep Power
    0

    Default

    ]well you would have to run some loops to add vast amount of data but it wouldn't be very difficult. there are many great tutorials how to use databases
    by flowing this link

  5. #5
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,762
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by ozzyman View Post
    ahh a database..... i was hoping to avoid databases but looks like it may be inevitable now.

    so instead of storing files, i would have to create new records into the database, but then... will the database be able to "hold" or store my data Objects directly? or will i need to run loops to fill in each record?
    It can be even easier than using MySql; nobody realizes it (because almost nobody reads the documentation) but if you've installed JSE 1.6 you have also downloaded and installed JavaDB (aka "Derby") which is a complete SQL database entirely written in Java. It comes with complete (good) documentation which also nobody reads. Give it a try, it's installed in its own directory next to your Java installation in the "Sun/JavaDB" directory.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  6. #6
    ozzyman's Avatar
    ozzyman is offline Senior Member
    Join Date
    Mar 2011
    Location
    London, UK
    Posts
    797
    Blog Entries
    2
    Rep Power
    4

    Default

    Thanks for that JosAh i'll definately have a look into it.

Similar Threads

  1. Storing video files in mysql database
    By mrvigneshmca in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 09-27-2009, 04:50 PM
  2. Storing Files
    By superwaxer in forum Advanced Java
    Replies: 6
    Last Post: 05-07-2009, 03:37 PM
  3. Storing and Retrieveing Data Using XStream & xml Files
    By geeeeky.girl in forum New To Java
    Replies: 0
    Last Post: 01-04-2009, 11:24 PM
  4. ANT (Another Neat Tool) - II
    By Java Tutorial in forum Java Tutorial
    Replies: 0
    Last Post: 05-24-2008, 03:44 PM
  5. ANT (Another Neat Tool)
    By Java Tutorial in forum Java Tutorial
    Replies: 0
    Last Post: 05-17-2008, 12:42 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
  •