Results 1 to 6 of 6
-
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'
- 03-26-2011, 05:54 PM #2
Member
- Join Date
- Feb 2010
- Posts
- 51
- Rep Power
- 0
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.
-
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?
- 03-26-2011, 06:30 PM #4
Member
- Join Date
- Feb 2010
- Posts
- 51
- Rep Power
- 0
]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
- 03-26-2011, 07:48 PM #5
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,394
- Blog Entries
- 7
- Rep Power
- 17
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,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
-
Similar Threads
-
Storing video files in mysql database
By mrvigneshmca in forum JavaServer Pages (JSP) and JSTLReplies: 1Last Post: 09-27-2009, 03:50 PM -
Storing Files
By superwaxer in forum Advanced JavaReplies: 6Last Post: 05-07-2009, 02:37 PM -
Storing and Retrieveing Data Using XStream & xml Files
By geeeeky.girl in forum New To JavaReplies: 0Last Post: 01-04-2009, 10:24 PM -
ANT (Another Neat Tool) - II
By Java Tutorial in forum Java TutorialReplies: 0Last Post: 05-24-2008, 02:44 PM -
ANT (Another Neat Tool)
By Java Tutorial in forum Java TutorialReplies: 0Last Post: 05-17-2008, 11:42 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks