Interestin dilemma - See if you can help :)

Thread Solved

Join Date: Nov 2009
Posts: 61
Reputation: P00dle is an unknown quantity at this point 
Solved Threads: 0
P00dle P00dle is offline Offline
Junior Poster in Training

Interestin dilemma - See if you can help :)

 
0
  #1
22 Days Ago
Hi,

I have stumbled on an interesting problem. I have thought 'n' thought, but haven't come up with any good ideas of how to handle this.

I have a text file that contains many records, but without the records being seperated. I need to figure out how to seperate these files, or at least how to write a program that recognizes different records and can then seperate them.

I don't expect anyone to write my program for me, but I need help seperating the records.

The beginning of every record looks like this: MSUBUGA JIMSON
P O BOX 21273
GABORONE
(Obviously they are all different, but always have 3 values on 3 lines.)
The end looks like this:
P107.17 P0.00 P225.08 P0.00 P332.25
(The numbers always vary, but there are always 5)

Any help will be greatly appreciated, Thank you.
Reply With Quote Quick reply to this message  
Join Date: Feb 2006
Posts: 2,357
Reputation: masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of 
Solved Threads: 252
Moderator
masijade's Avatar
masijade masijade is offline Offline
Nearly a Posting Maven
 
1
  #2
22 Days Ago
BufferedReader, readLine, a counter, and String's split.
Java Programmer and Sun Systems Administrator

----------------------------------------------

Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
Reply With Quote Quick reply to this message  
Join Date: Nov 2009
Posts: 5
Reputation: ushi324 is an unknown quantity at this point 
Solved Threads: 1
ushi324 ushi324 is offline Offline
Newbie Poster
 
1
  #3
22 Days Ago
Hi..
You can use fileReader. Like an example :

FileReader reader = new FileReader( “file.txt" ) ;
BufferedReader in = new BufferedReader( reader ) ;

InputStream, readLIne
Reply With Quote Quick reply to this message  
Join Date: Nov 2009
Posts: 61
Reputation: P00dle is an unknown quantity at this point 
Solved Threads: 0
P00dle P00dle is offline Offline
Junior Poster in Training
 
0
  #4
22 Days Ago
Thank you for all the quick replies.

I won't mark this thread as solved just yet, as I may have more questions later, but I will both ways and see what happens.

Great work guys
I wanted to ask God for a bike, but I know thats not how he does things, so I stole one and asked for forgiveness.
Reply With Quote Quick reply to this message  
Join Date: Nov 2009
Posts: 61
Reputation: P00dle is an unknown quantity at this point 
Solved Threads: 0
P00dle P00dle is offline Offline
Junior Poster in Training
 
0
  #5
22 Days Ago
Eek!

Well, both ways worked. I handed in my project. Boss was satisfied.

The client gave us the wrong data though :/

Is there any way in java to determine whether or not a line of data is binary or text? e.g. it will always be one of the two.

Is there a method like [var].isBinary() or something? If so, which library should I import for it. I'm stumped. Googl'ing has proved fruitless so far, and I need to get this done by tomorrow this time.

Please help.
I wanted to ask God for a bike, but I know thats not how he does things, so I stole one and asked for forgiveness.
Reply With Quote Quick reply to this message  
Join Date: Feb 2006
Posts: 2,357
Reputation: masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of 
Solved Threads: 252
Moderator
masijade's Avatar
masijade masijade is offline Offline
Nearly a Posting Maven
 
0
  #6
22 Days Ago
Well, text, is also "binary". If what you're reading might contain something that is not strictly plain text, then use a BufferedInputStream (with FileInputStream), rather than reader and convert the text parts to text with new String(byte[]).
Java Programmer and Sun Systems Administrator

----------------------------------------------

Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
Reply With Quote Quick reply to this message  
Join Date: Nov 2009
Posts: 61
Reputation: P00dle is an unknown quantity at this point 
Solved Threads: 0
P00dle P00dle is offline Offline
Junior Poster in Training
 
0
  #7
22 Days Ago
Originally Posted by masijade View Post
Well, text, is also "binary". If what you're reading might contain something that is not strictly plain text, then use a BufferedInputStream (with FileInputStream), rather than reader and convert the text parts to text with new String(byte[]).
Thanks masijade!

Im going to try the following:
  1. byte bytearray [] = test.getBytes();
  2. System.out.println("Test string : " + test);
  3.  
  4. CharsetDecoder d = Charset.forName("US-ASCII").newDecoder();
  5. try {
  6. CharBuffer r = d.decode(ByteBuffer.wrap(bytearray));
  7. r.toString();
  8. }
  9. catch(CharacterCodingException e) {
  10. System.out.println("only regular ASCII characters please!");
  11. // interrupt the processing
  12. throw new Exception(e);
  13. }
  14. System.out.println("Ok, it's ASCII only!");
I wanted to ask God for a bike, but I know thats not how he does things, so I stole one and asked for forgiveness.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC