| | |
Reading in from files?
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Oct 2009
Posts: 10
Reputation:
Solved Threads: 0
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
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
•
•
Join Date: Oct 2009
Posts: 92
Reputation:
Solved Threads: 8
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.
StringBuilder
http://java.sun.com/javase/6/docs/ap...ngBuilder.html
Once you've done that, you can remove and modify anything you want.
0
#3 Nov 11th, 2009
Java Syntax (Toggle Plain Text)
String txt = ""; while ((line_in = bufferedReader.readLine()) != null) { txt = txt + line_in; // Now you will handle txt, not the input }
Hope this helps
I would like a steaming pile of coolbeans smothered in spicy awesomesauce please, with a side of scrambled win.
![]() |
Similar Threads
- Help with Reading in files! (Python)
- reading multiple text files (Java)
- Reading and writing from files works selectively... (C++)
- files in VB 6.0 (Visual Basic 4 / 5 / 6)
- Downloading files from websites (Java)
- While loop not ending when reading from file (C++)
- Problems reading from files (C)
Other Threads in the Java Forum
- Previous Thread: help building Java Tree from .txt file
- Next Thread: findInLine(“.”)charat(0);
| Thread Tools | Search this Thread |
Tag cloud for Java
-xlint android animated api appinventor apple applet application arguments array arrays automation bi binary blackberry bluetooth chat class classes client code compile compiler component database draw eclipse error event exception file fractal freeze functiontesting game gameprogramming givemetehcodez graphics gui health helpwithhomework html ide image input integer j2me java javaprojects jetbrains jmf jni jpanel jtable julia learningresources linux list login loop main map method methods mobile myregfun netbeans newbie notdisplaying number object oracle page print problem program programming project qt recursion scanner screen server set size sms socket sort spamblocker sql string swing system test threads time tree variablebinding windows xor





