473,394 Members | 1,770 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Reading and Writing From a Delimited File

I'm a relative newbie to Java, but I'm working on a project. I want to take the input from a Java GUI and store it in a text file. I also want to be able to take that same file and read it back to the GUI. The idea here is to, say, store a customer's purchases in a single file, and allow the user to view a particular customer's purchases. Let's say the input looks like this:

John 3-18-2012 Hammer
Bill 3-14-2012 Nail
John 2-8-2012 Broom
Randy 2-5-2012 Rake

I want the user to be able to pull up all of John's(or whoever) purchases. I also want to be able to add records to this file in case Randy ever comes back and buys something else.

I'm thinking that sorting the data according to the customer as it comes in would make it quicker in searching for the correct customer later. I'd like to load the file upon opening the "recordManagement" class, and an array needs to be in there somewhere.

I'm pretty sure I'm looking at FileWriter, BufferedWriter, PrintWriter, BufferedReader, and/or FileReader.

But, even looking at examples, I've having trouble even figuring out where to start for my particular project. Any help would be appreciated.
Mar 20 '12 #1
5 2472
r035198x
13,262 8TB
Why not store that information into a database instead of a file?
If you really want to use the file then see this article about how to read/write files: http://bytes.com/topic/java/insights...-writing-files
Mar 21 '12 #2
That's actually brilliant, except I have no working knowledge of how to connect my GUI input to the database. I've googled around, but I'm still relatively clueless. Would you provide a good link for what I'm trying to do, or maybe a simple example of where to start?
Mar 21 '12 #3
Expand|Select|Wrap|Line Numbers
  1. //try this code is for mdb connection.
  2. import jaca.sql.*;
  3. public class test1
  4. {
  5. public static void main(String [] args) {
  6. String myDsn = "mdbTst";
  7. String dbUrl = "jdbc:odbc:"+myDsn;
  8. try {
  9. Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
  10. Connection con = DriverManager.getConnection(dbUrl,"","");
  11. Statement s = con.createStatement();
  12. s.execute("create table tst(fld_num integer)");
  13. s.execute("insert into fld_num values(123)");
  14. s.execute("select * from tst");
  15.  
  16. ResultSet rs = s.getResultSet();
  17. if(rs!=null) {
  18. while(rs.next()) {
  19. System.out.println("Data from fld_num:"+rs.getString(1));
  20. }
  21. s.execute("drop table tst");
  22. s.close();
  23. con.close();
  24. }
  25. catch(Exception err) {
  26. System.out.println("Error:"+err);
  27. }
  28. }
  29. }
  30.  
Mar 22 '12 #4
oops, i mean import java.sql.*;

//you need to create System dsn then name this connection as mdbTst then browse your database..
//you can do this in your odbc manager, can be located in control pannel, administrative tools, ODBC Management.

//this code is just for giving some idea..
//even i dont have a knowledge how to connect java in other type of database.
// i saw this code via google. =)
Mar 22 '12 #5
r035198x
13,262 8TB
Rather prefer JDBC instead of ODBC.
There's a very good tutorial here:http://docs.oracle.com/javase/tutori...ics/index.html
Mar 22 '12 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Dot Kom | last post by:
I've got this text file full of lines like: A*1King Richard Dale*3Welton Orchard Rd*4Petersburg*5257-1234Î the columns are defined by the *#, so that line would break apart like: A*1King...
3
by: monte | last post by:
Hello, I need to parse a tilde delimited file and output it to a tabbed delimited file. Example file example.txt data1~data2~data3~data4 data5~data6~data7~data8 I need to extract data2,...
1
by: John Beavers | last post by:
I have a file that is tab delimited and has no header row with column headings. What is the best method for reading this data into a dataset?
1
by: ungvichian | last post by:
So, right now I'm writing a program in VC++.Net with MFC, and one of the steps involves reading numeric values from a comma delimited file (like 4.56, 2.44, 3.453 etc.). The only methods I've been...
1
by: Corey Ellsworth | last post by:
Does anybody know how to read/write extended file properties such as comments, keywords, author, etc. in VB.NET? I can't find anything anywhere. It may be because I don't know where to start or...
1
by: j7.henry | last post by:
I am trying to pull specific data that is in a comma delimited file into a web page. So if my comma delimited file looks like: Name,Address,Zip Fred,123 Elm,66666 Mike,23 Jump,11111 I would...
3
by: al jones | last post by:
I’m using textfieldparser to read a data file. which contains, for example: Amondó Szegi Amondo Szegi andré nossek André Nossek © Characte Character Note the vowels with diacriticals...
1
jwwicks
by: jwwicks | last post by:
Hello All, This is a student assignment. So I don't want the complete answer just a hint or maybe a bumb on the head cause I'm doing it the wrong way. Assume I haven't done anything braindead like...
2
by: vishalgupta | last post by:
i need to read/write to a text/binary file without using any header file in c. i cant use the FILE strucutire as it is defined in stdio.h nor can i use file input/output functions as they are...
7
by: kimmelsd33 | last post by:
I am using VB6. I want to read a tab delimited file, and assign each column value into a variable. If the variable is "-999.25", I want to make it a "0". I then want to reassemble the values, and...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.