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.

1234 5th St
Orlando, Fl 19191

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.


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


You can try the StringTokenizer which allows special delimeters. Also, I'm not sure a 2D array is the best way to go, but can't say for a fact that it's not. If you post your parsing code we could probably help more.

import cs1.Keyboard;
import java.util.*;
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;
			line = in.readLine();
			while (line != null && line != "\n")
				addyArray[i][a] = line;
				line = in.readLine();
				if (line == null) line = "\n";
			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]);
This article has been dead for over six months. Start a new discussion instead.