how to splite a Reader-file into 2 dimensional array?

package readtext;

import java.io.*;// For input & output classes

import java.util.Date;// For the Date class

public class input {

public input() {

}

public static void main(String[] args)

{

try

{

String dirName = "C:/Documents and Settings/seng/Desktop/testfile"; // Directory for the output file

String fileName = "data.txt"; // Name of the output file

File output = new File(dirName, fileName);

output.createNewFile();// Create a new file if necessary

if(!output.isFile())// Verify we have a file

{

System.out.println("Creating " + output.getPath() + " failed.");

return;

}

BufferedWriter out = new BufferedWriter(

new FileWriter(output.getPath(), true));

BufferedReader in = new BufferedReader(

new FileReader("C:/Documents and Settings/seng/Desktop/testfile/txt.txt"));

String[] text = {in.readLine()};// String to be segmented

// Write the proverbs to the file preceded by the string length

for(int i = 0; i < text.length; i++)//read the whole line

{

out.write(text);

out.flush();

}

out.close();

}

catch(IOException e)

{

System.out.println("Error writing the file " + e);

}

}

}

currently i have a data.txt which contain of 3 x 3 data

123

456

7 89

the information do not arrange properly.

if i using the readLine() to read the string, then i will only get the 1st row data (1 23) output in the txt.txt file..may i know that any1 know how to get for the 2nd and 3rd row of data?

Message was edited by:

wilfrid100

[1712 byte] By [wilfrid100a] at [2007-10-3 2:21:18]
# 1
As the name implies the readLine method read only one line. If you want to read multiple lines you must put it inside a loop.Hint: readLine method will return null when you hit the buttom of the file
LRMKa at 2007-7-14 19:20:14 > top of Java-index,Java Essentials,New To Java...
# 2

Change you code like this and run

String textLine=null;

while((textLine=in.readLine())!=null)

{

String[] text = textLine; // String to be segmented

// Write the proverbs to the file preceded by the string length

for(int i = 0; i < text.length; i++) //read the whole line

{

out.write(text);

out.flush();

}

}

JBNa at 2007-7-14 19:20:14 > top of Java-index,Java Essentials,New To Java...
# 3
thank you for ur help....now i can read for the full text...
wilfrid100a at 2007-7-14 19:20:14 > top of Java-index,Java Essentials,New To Java...