| | |
Parsing Text file
![]() |
•
•
Join Date: Apr 2005
Posts: 5
Reputation:
Solved Threads: 0
Alright, This is really bothering me that I can't figure this out since I took 3 terms of Java.
Alright, I have a text file that contains addresses.
ex:
Name
1234 5th St
Orlando, Fl 19191
Name2
1423 4th ave
New York, NY 09987
and so on and so on.
Originally I was trying to have it take each line and put it into an 2d array.
addyArray[addyIndex][lineOfAddy].
I could not figure out how to make a linebreak (gap) be the delimiter to separate the values.
Most of the addresses will be 3lines, but I wanted the expandability of being able to handle 4 line addies.
Can anyone help me with this? If you need more details either post in here or email me at nscelica@yahoo.com.
Thanks
Alright, I have a text file that contains addresses.
ex:
Name
1234 5th St
Orlando, Fl 19191
Name2
1423 4th ave
New York, NY 09987
and so on and so on.
Originally I was trying to have it take each line and put it into an 2d array.
addyArray[addyIndex][lineOfAddy].
I could not figure out how to make a linebreak (gap) be the delimiter to separate the values.
Most of the addresses will be 3lines, but I wanted the expandability of being able to handle 4 line addies.
Can anyone help me with this? If you need more details either post in here or email me at nscelica@yahoo.com.
Thanks
•
•
Join Date: Apr 2005
Posts: 5
Reputation:
Solved Threads: 0
Java Syntax (Toggle Plain Text)
import cs1.Keyboard; import java.util.*; import java.io.*; public class PrintAddresses { public static void main (String[] args) throws IOException { String [][] addyArray = new String[50][4]; for (int j=0; j<50; j++) { for (int k=0; k<4; k++) { addyArray[j][k] = "\n"; } } // FileWriter outFile = new FileWriter ("results.txt"); // PrintWriter out = new PrintWriter(outFile); FileReader inFile = new FileReader (args[0]); BufferedReader in = new BufferedReader (inFile); String line = ""; int i = 0, a = 0; while(in.ready()) { line = in.readLine(); while (line != null && line != "\n") { addyArray[i][a] = line; line = in.readLine(); a++; if (line == null) line = "\n"; } i++; a = 0; } for(int j=0; j<3; j++) { for(int k=0;k<4;k++) { System.out.println((j+1) + "-" + (k+1) + " " + addyArray[j][k]); } } } }
![]() |
Similar Threads
- Newbie C++ Search and Parsing Text file. (C++)
- connect to text file database (Visual Basic 4 / 5 / 6)
- Parsing a log file using regular expressions (C#)
- text file strings help (Visual Basic 4 / 5 / 6)
- MySql commands in a text file (PHP)
- Parsing a .asn file (Community Introductions)
- Store Bluetooth remote address to a text file (C++)
- 10 line text file (Java)
- Read and write to an ASCII Text file (Java)
Other Threads in the Java Forum
- Previous Thread: Quick Project Question{
- Next Thread: Programming for Cell Phones
| Thread Tools | Search this Thread |
account android applet application apps array automation awt bidirectional binary birt bluetooth businessintelligence busy_handler(null) card class classes client code collision columns component constructor database designadrawingapplicationusingjavajslider draw eclipse error eventlistener exception expand fractal free game givemetehcodez graphics gui guidancer homework html ide image inheritance integer integration intellij j2me java javafx javamicroeditionuseofmotionsensor javaprojects jlabel jme jni jpanel jtextfield jtree julia linux loop method midlethttpconnection migrate mobile mobiledevelopmentcreatejar monitoring myaggfun netbeans newbie nullpointerexception open-source oracle plazmic print problem program property ria scanner server set sharepoint smart sms smsspam sourcelabs splash sql sqlite subclass support swing testautomation textfield threads tree trolltech unlimited utility windows






