Reading in from files?

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Oct 2009
Posts: 10
Reputation: skiplatte is an unknown quantity at this point 
Solved Threads: 0
skiplatte skiplatte is offline Offline
Newbie Poster

Reading in from files?

 
0
  #1
Nov 9th, 2009
Hi, is there a way to read in a file to give a string which is passed to the method without reading line by line? I need to read in something like this...

1 MLRLPTVFRQ MRPVSRVLAP HLTRAYAKDV KFGADARALM LQGVDLLADA
51 VAVTMGPKGR TVIIEQSWGS PKVTKDGVTV AKSIDLKDKY KNIGAKLVQD
101 VANNTNEEAG DGTTTATVLA RSIAKEGFEK ISKGANPVEI RRGVMLAVDA
151 VIAELKKQSK PVTTPEEIAQ VATISANGDK EIGNIISDAM KKVGRKGVIT
201 VKDGKTLNDE LEIIEGMKFD RGYISPYFIN TSKGQKCEFQ DAYVLLSEKK
251 ISSIQSIVPA LEIANAHRKP LVIIAEDVDG EALSTLVLNR LKVGLQVVAV
301 KAPGFGDNRK NQLKDMAIAT GGAVFGEEGL TLNLEDVQPH DLGKVGEVIV
351 TKDDAMLLKG KGDKAQIEKR IQEIIEQLDV TTSEYEKEKL NERLAKLSDG
401 VAVLKVGGTS DVEVNEKKDR VTDALNATRA AVEEGIVLGG GCALLRCIPA
451 LDSLTPANED QKIGIEIIKR TLKIPAMTIA KNAGVEGSLI VEKIMQSSSE
501 VGYDAMAGDF VNMVEKGIID PTKVVRTALL DAAGVASLLT TAEVVVTEIP
551 KEEKDPGMGA MGGMGGGMGG GMF

...as a continuous string. I have methods in my class which capitalise and remove numbers/spaces, but it seems to only be reading the first line (even when I put this in as user input). I'm thinking this is probably because of input.Readline() only reading the first line rather than a problem with the regex??

Many thanks
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 92
Reputation: thines01 is an unknown quantity at this point 
Solved Threads: 8
thines01 thines01 is offline Offline
Junior Poster in Training
 
0
  #2
Nov 9th, 2009
If the data is separated by linefeeds and/or carriage returns, just read it in line by line and concatenate the lines together.

StringBuilder
http://java.sun.com/javase/6/docs/ap...ngBuilder.html

Once you've done that, you can remove and modify anything you want.
Reply With Quote Quick reply to this message  
Join Date: Nov 2009
Posts: 83
Reputation: P00dle is an unknown quantity at this point 
Solved Threads: 1
P00dle's Avatar
P00dle P00dle is offline Offline
Junior Poster in Training
 
0
  #3
Nov 11th, 2009
  1. String txt = "";
  2. while ((line_in = bufferedReader.readLine()) != null) {
  3. txt = txt + line_in;
  4. // Now you will handle txt, not the input
  5. }

Hope this helps
I would like a steaming pile of coolbeans smothered in spicy awesomesauce please, with a side of scrambled win.
Reply With Quote Quick reply to this message  
Reply

Message:


Thread Tools Search this Thread



Tag cloud for Java
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC